From 0e958a72e1780138e68c799792190085cf505ee7 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 8 Nov 2024 12:48:57 +0000 Subject: tar: try harder to detect old tar files The code to autodetect compressed tar files failed to detect a bunzip2-compressed archive. When tar was invoked with the 'j' option it worked fine. The autodetection code looks for the magic string 'ustar' or a series of five NULs to determine that an archive is uncompressed. The failing archives had more than five NULs in the header and were taken to be uncompressed. Look for a longer run of NULs: 16 is certainly sufficient for the archives in question. Adds 8-16 bytes. (GitHub issue #475) --- archival/libarchive/get_header_tar.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c index cc6f3f0ad..5fd5a7980 100644 --- a/archival/libarchive/get_header_tar.c +++ b/archival/libarchive/get_header_tar.c @@ -239,8 +239,13 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) /* Check header has valid magic, "ustar" is for the proper tar, * five NULs are for the old tar format */ if (!is_prefixed_with(tar.magic, "ustar") +#if !ENABLE_PLATFORM_MINGW32 && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY || memcmp(tar.magic, "\0\0\0\0", 5) != 0) +#else + && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY + || memcmp(tar.magic, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) != 0) +#endif ) { #if ENABLE_FEATURE_TAR_AUTODETECT autodetect: -- cgit v1.2.3-55-g6feb