瀏覽代碼

Improve compression format recognition

Some comressed archives can pass the checksum test, which makes tar
treat them as uncompressed archives.

* src/buffer.c (check_compressed_archive): Test the checksum only
if the block we read looks like a valid tar header (i.e. has
a magic string).
Sergey Poznyakoff 10 年之前
父節點
當前提交
1847ec67ce
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      src/buffer.c

+ 4 - 1
src/buffer.c

@@ -391,7 +391,10 @@ check_compressed_archive (bool *pshort)
   /* Restore global values */
   read_full_records = sfr;
 
-  if (tar_checksum (record_start, true) == HEADER_SUCCESS)
+  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)
     /* Probably a valid header */
     return ct_tar;