0% found this document useful (0 votes)
44 views

Does Gzip Add Integrity CRC Check To Tar - Stackexchange

Gzip adds integrity checking to tar files through CRC checksums. When tar files are compressed with gzip, gzip calculates and stores a 32-bit CRC checksum for the contents. This checksum can later be used to verify that the decompressed contents are intact and have not been corrupted. However, the checksum only detects errors rather than correcting them, so integrity is only ensured for detection of corruption, not recovery of corrupted data. Using an error correcting format like par may provide better integrity for unreliable storage or transfer.

Uploaded by

arunraj03
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Does Gzip Add Integrity CRC Check To Tar - Stackexchange

Gzip adds integrity checking to tar files through CRC checksums. When tar files are compressed with gzip, gzip calculates and stores a 32-bit CRC checksum for the contents. This checksum can later be used to verify that the decompressed contents are intact and have not been corrupted. However, the checksum only detects errors rather than correcting them, so integrity is only ensured for detection of corruption, not recovery of corrupted data. Using an error correcting format like par may provide better integrity for unreliable storage or transfer.

Uploaded by

arunraj03
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

 

Does gzip add integrity/crc check to a .tar?


Asked
6 years, 9 months ago Active
6 years, 2 months ago Viewed
15k times

I run commands:

13 tar -cf myArchive.tar myDirectory/

gzip myArchive.tar

then I copy the file over a lot of unreliable mediums, and later I unpack it using:
1
tar -xzf myArchive.tar.gz

The fact that I compressed the tar-ball, will that in any way guarantee the integrity, or at least a CRC of the unpacked content?

tar gzip checksum integrity

Share Improve this question Follow edited Oct 9 '14 at 13:33 asked Oct 9 '14 at 9:39
peterh Aksel Willgert
7,495 15 46 75 377 2 3 8

5 Answers Active Oldest Votes

tar itself does not write down a checksum for later comparsion. If you gzip the tar archive you can have that functionality.

16 tar uses compress . If you use the -Z flag while creating the archive tar will use the compress program when reading or writing the archive.
From the gzip manpage:

The standard compress format was not designed to allow consistency


checks.

But, you can use the -z parameter. Then tar reads and writes the archive through gzip . And gzip writes a crc checksum. To display that
checksum use that command:

$ gzip -lv archive.tar.gz

method crc date time compressed uncompressed ratio uncompressed_name

defla 3f641c33 Sep 25 14:01 24270 122880 80.3% archive.tar

From the gzip manpage:

When using the first two formats (gzip or zip is meant), gunzip checks
a 32 bit CRC.

Share Improve this answer Follow edited Oct 9 '14 at 14:46 answered Oct 9 '14 at 10:10
Mitch chaos
1,028 2 12 23 43.5k 10 105 136

Yes, the gzip file format contains a CRC-32 checksum that can be used to detect if the archive has been corrupted.

5 Of course, while the checksum lets gzip tell you that the archive is corrupted, it doesn't actually do anything to help you recover the data inside
the archive. Thus, it's mostly useful for things like checking that an archive you just downloaded off the web really was downloaded correctly.

If you're actually worried about storing or transmitting your archives over unreliable media, you may want to consider using an archive format like
par that actually provides error correction in addition to error detection. Of course, the down side of such formats is that the redundancy needed
for error correction necessarily increases the file size somewhat.

Share Improve this answer Follow answered Oct 9 '14 at 14:43


Ilmari Karonen
1,403 10 13

tar does not have an integrity check.


Example:

5 $ echo JJJJJJJJJJJJJJJJJJ > b

$ tar cvf a.tar b

$ sed -i s/JJJJJJJJJJJJJJJJJJ/tttttttttttttttttt/g a.tar

$ tar xvf a.tar

$ cat b

tttttttttttttttttt

See, the content of a.tar archive changed, so the file b has completely different content, but tar did not notice this.
This is true for any tar,
including tar-1.28 (latest) with both tar formats --format=gnu --format=posix . The pax command (alternative tar reader) pax -r < a.tar also
does not notice archive changes.

Share Improve this answer Follow edited May 17 '15 at 3:10 answered May 16 '15 at 20:10
G-Man Says 'Reinstate user115641
Monica' 61 1 2
18.8k 24 53 104

2 The OP seems to be aware (or at least suspect) that tar (at least without the -z option) does not do integrity checking.  Also, the accepted answer states this. 
The question is: does gzip (or the use of the -z option) add integrity checking?
– G-Man Says 'Reinstate Monica'
May 16 '15 at 22:05

correct G-Man, This could be an okay answer if it also included the gzip part and demonstrates that gzip does detect that the content has changed.
– 
Aksel Willgert
May 17 '15 at 12:54

If tar finds errors when unpacking, it will print a message and exit with a non-zero exit value. This behavior is independent from the compression
algorithm used after the tar file has been created.
2
If you want to verify that the file was successfully sent to the destination over an unreliable link, then create a md5 sum of the file prior to sending
and verify the md5 sum after the reception.

Share Improve this answer Follow answered Oct 9 '14 at 9:56


Jan
6,832 28 39

if im only interested in the integrity of the unpacked content. md5 on the tar doesnt add anything extra compared to the check tar does during unpackinng?
– 
Aksel Willgert
Oct 9 '14 at 10:03

The integrity of the content inside the tar archive is taken care of by tar itself. You could add an additional layer if needed: If the tar file's integrity is verified, then
the content inside the tar archive is OK, too. But all that should be taken care of by the protocol used to transfer the data in the first place.
– Jan
Oct 9 '14 at 10:09

You might also like