I wrote a function that checks for a corrupted archive using a CRC checksum.To test it, I just opened the archive and scrambled the content with a hex editor. The problem is that I do not believe that this is the correct way to generate a corrupted file.Is there any other way to create a controlled corruption, so it won't be totally random but can simulate what happens with real corrupted archives? I never had to corrupt something on purpose so I am not really sure how to do so, beside the random scrambling of data in a file.
How to corrupt an archive file in a controlled way?
files;corruption
I haven't done much fuzz testing either, but here's two ideas:Write some zeroes into the middle of the file.  Use dd with conv=notrunc.dd if=/dev/zero of=file_to_fuzz.zip bs=1 count=1 seek=N conv=notruncUsing /dev/urandom as a source is also an option.Alternatively, punch multiple-of-4k holes with fallocate --punch-hole.  You could even fallocate --collapse-range to cut out a page without leaving a zero-filled hole.  (This will change the file size).A download resumed at the wrong place would match the --collapse-range scenario.  And incomplete torrent will match the punch-hole scenario.  (sparse file or pre-allocated extent, reads as zeros anywhere that hasn't been written yet.)Bad RAM (in the system you downloaded the file from) can cause corruption, and so can optical drives can also corrupt files (their ECC isn't always strong enough to recover perfectly from scratches or fading of the dye).DVD sectors (ECC blocks) are 2048B, but single byte or even single-bit errors can happen.  Some drives will probably give you the bad data uncorrectable data instead of a read-error for the sector, if you read in raw mode, or w/e it's called.