[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-tar] 'BZh[1-9]' file in v7 format archive confuses GNU tar
From: |
Sergey Poznyakoff |
Subject: |
Re: [Bug-tar] 'BZh[1-9]' file in v7 format archive confuses GNU tar |
Date: |
Wed, 28 Nov 2018 14:32:14 +0200 |
Michał Górny <address@hidden> ha escrit:
> FWICS the problem is that one of the checksum variants evaluates to zero
> and tar is rather lax on accepting null checksum string (with trailing
> garbage) as zero.
That's easy to fix (see the attached patch). I'm not quite convinced
that it doesn't break backward compatibility though (can such headers be
found in some old archives?)
Regards,
Sergey
diff --git a/src/buffer.c b/src/buffer.c
index ddb63cc..5632aee 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -406,10 +406,6 @@ check_compressed_archive (bool *pshort)
read_full_records = sfr;
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;
diff --git a/src/list.c b/src/list.c
index ba9c306..0dacbb7 100644
--- a/src/list.c
+++ b/src/list.c
@@ -892,6 +892,11 @@ from_header (char const *where0, size_t digs, char const
*type,
value = -value;
}
+ /* Skip consecutive \0's. This ensures the test below will catch eventual
+ trailing garbage */
+ while (where < lim && !*where)
+ where++;
+
if (where != lim && *where && !isspace ((unsigned char) *where))
{
if (type)