|
|
58251f |
From bb9b157146a62e655fb369b32684398c949fa1b1 Mon Sep 17 00:00:00 2001
|
|
|
58251f |
From: Tim Kientzle <kientzle@acm.org>
|
|
|
58251f |
Date: Sat, 21 Feb 2015 09:36:23 -0800
|
|
|
58251f |
Subject: [PATCH] Issue 407: Tar reader tries to examine last character of an
|
|
|
58251f |
empty filename
|
|
|
58251f |
|
|
|
58251f |
Of interest: While working on this, I noted that we have
|
|
|
58251f |
an existing test for tar files with empty filenames.
|
|
|
58251f |
That test asserts that the correct behavior here is for the
|
|
|
58251f |
format handler to return the entry with the empty filename
|
|
|
58251f |
and a status of ARCHIVE_OK. Clients need to be robust against
|
|
|
58251f |
empty filenames.
|
|
|
58251f |
---
|
|
|
58251f |
libarchive/archive_read_support_format_tar.c | 20 ++++++++------------
|
|
|
58251f |
1 file changed, 8 insertions(+), 12 deletions(-)
|
|
|
58251f |
|
|
|
58251f |
diff --git a/libarchive/archive_read_support_format_tar.c b/libarchive/archive_read_support_format_tar.c
|
|
|
58251f |
index 37399a0..1e78093 100644
|
|
|
58251f |
--- a/libarchive/archive_read_support_format_tar.c
|
|
|
58251f |
+++ b/libarchive/archive_read_support_format_tar.c
|
|
|
58251f |
@@ -456,6 +456,7 @@ archive_read_format_tar_read_header(struct archive_read *a,
|
|
|
58251f |
static int default_dev;
|
|
|
58251f |
struct tar *tar;
|
|
|
58251f |
const char *p;
|
|
|
58251f |
+ const wchar_t *wp;
|
|
|
58251f |
int r;
|
|
|
58251f |
size_t l, unconsumed = 0;
|
|
|
58251f |
|
|
|
58251f |
@@ -506,27 +507,22 @@ archive_read_format_tar_read_header(struct archive_read *a,
|
|
|
58251f |
}
|
|
|
58251f |
}
|
|
|
58251f |
|
|
|
58251f |
- if (r == ARCHIVE_OK) {
|
|
|
58251f |
+ if (r == ARCHIVE_OK && archive_entry_filetype(entry) == AE_IFREG) {
|
|
|
58251f |
/*
|
|
|
58251f |
* "Regular" entry with trailing '/' is really
|
|
|
58251f |
* directory: This is needed for certain old tar
|
|
|
58251f |
* variants and even for some broken newer ones.
|
|
|
58251f |
*/
|
|
|
58251f |
- const wchar_t *wp;
|
|
|
58251f |
- wp = archive_entry_pathname_w(entry);
|
|
|
58251f |
- if (wp != NULL) {
|
|
|
58251f |
+ if ((wp = archive_entry_pathname_w(entry)) != NULL) {
|
|
|
58251f |
l = wcslen(wp);
|
|
|
58251f |
- if (archive_entry_filetype(entry) == AE_IFREG
|
|
|
58251f |
- && wp[l-1] == L'/')
|
|
|
58251f |
+ if (l > 0 && wp[l - 1] == L'/') {
|
|
|
58251f |
archive_entry_set_filetype(entry, AE_IFDIR);
|
|
|
58251f |
- } else {
|
|
|
58251f |
- p = archive_entry_pathname(entry);
|
|
|
58251f |
- if (p == NULL)
|
|
|
58251f |
- return (ARCHIVE_FAILED);
|
|
|
58251f |
+ }
|
|
|
58251f |
+ } else if ((p = archive_entry_pathname(entry)) != NULL) {
|
|
|
58251f |
l = strlen(p);
|
|
|
58251f |
- if (archive_entry_filetype(entry) == AE_IFREG
|
|
|
58251f |
- && p[l-1] == '/')
|
|
|
58251f |
+ if (l > 0 && p[l - 1] == '/') {
|
|
|
58251f |
archive_entry_set_filetype(entry, AE_IFDIR);
|
|
|
58251f |
+ }
|
|
|
58251f |
}
|
|
|
58251f |
}
|
|
|
58251f |
return (r);
|
|
|
58251f |
--
|
|
|
58251f |
2.7.4
|
|
|
58251f |
|