Does Gzip Add Integrity CRC Check To Tar - Stackexchange
Does Gzip Add Integrity CRC Check To Tar - Stackexchange
I run commands:
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?
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
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:
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:
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.
$ 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.
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