summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Raiskup <praiskup@redhat.com>2017-03-30 13:30:15 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2017-05-29 16:12:48 +0300
commit1e8b786e651d174a5fc9bf63a08d00c2d592ee3e (patch)
tree0ae1b1b4ad2d4c29ca8b4d742f028575ef682aee
parent8b9026f3ae8c03942cb9f8a3593895d5eec82b32 (diff)
downloadtar-1e8b786e651d174a5fc9bf63a08d00c2d592ee3e.tar.gz
Fix non-deterministic archive type detection
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.
-rw-r--r--src/buffer.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 57fe813a..6f96c2fa 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -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;