Force gzip to decompress despite CRC error

15,724

You said "unzip", but the question says "gzip". Which is it? Those are two different programs that operate on two different formats. I will assume gzip. Also the length is not "indicated by the CRC". The gzip trailer contains a CRC and an uncompressed length (modulo 232), which are two different things.

The gzip command will decompress all valid deflate data and write it out before checking the crc. So if, for example, I take a .gz file and corrupt just the crc (or length) at the end, and do:

gzip -dc < corrupt.gz > result

then result will be the entire, correct uncompressed data stream. There is no need to modify and recompile gzip, nor to write your own ungzipper. gzip will complain about the crc, but all of the data will be written nevertheless.

Share:
15,724
user1777900
Author by

user1777900

Updated on August 05, 2022

Comments

  • user1777900
    user1777900 almost 2 years

    I think there's a way to do this but I'm not sure how? Basically, I was writing a compression program that resulted in a crc error when I tried to unzip the compressed data. Normally this means that the decompressor actually recognized my data as being in the right format and decompressed it, but when it compared the result to the expected length as indicated by the CRC, they weren't the same.

    However, for comparison reasons, I actually do want to see the output to see if it's just a concatenation issue (which should be relatively obvious if the decompressed output isn't gibberish but just in the wrong order).