]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Fix non-deterministic archive type detection
authorPavel Raiskup <praiskup@redhat.com>
Thu, 30 Mar 2017 11:30:15 +0000 (13:30 +0200)
committerSergey Poznyakoff <gray@gnu.org.ua>
Mon, 29 May 2017 13:12:48 +0000 (16:12 +0300)
Due to analysis of partly uninitialized read-ahead buffer
(short_read call), we sometimes mistakenly classified very small
compressed archives as non-compressed; which in turn caused
extraction failure.

* src/buffer.c (check_compressed_archive): Don't assume that
archives smaller than BLOCKSIZE could be non-compressed, as tar
header always has at least one block.

src/buffer.c

index 57fe813ada809f65af3d62c3941a7c5d789ff26e..6f96c2fa6aa69943cb5b63c1e140eeb1e341ea0b 100644 (file)
@@ -402,10 +402,12 @@ check_compressed_archive (bool *pshort)
   /* Restore global values */
   read_full_records = sfr;
 
-  if ((strcmp (record_start->header.magic, TMAGIC) == 0 ||
-       strcmp (record_start->buffer + offsetof (struct posix_header, magic),
-              OLDGNU_MAGIC) == 0) &&
-      tar_checksum (record_start, true) == HEADER_SUCCESS)
+  if (record_start != record_end /* no files smaller than BLOCKSIZE */
+      && (strcmp (record_start->header.magic, TMAGIC) == 0
+          || strcmp (record_start->buffer + offsetof (struct posix_header,
+                                                      magic),
+                     OLDGNU_MAGIC) == 0)
+      && tar_checksum (record_start, true) == HEADER_SUCCESS)
     /* Probably a valid header */
     return ct_tar;