Skip to content

Commit 661ee10

Browse files
committed
Do not overwrite pathname in header_old_tar() if already
set in header_gnu_longname()
1 parent 75cdc59 commit 661ee10

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

libarchive/archive_read_support_format_tar.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,9 +1521,17 @@ header_old_tar(struct archive_read *a, struct tar *tar,
15211521
const struct archive_entry_header_ustar *header;
15221522
int err = ARCHIVE_OK, err2;
15231523

1524-
/* Copy filename over (to ensure null termination). */
1524+
/*
1525+
* Copy filename over (to ensure null termination).
1526+
* Skip if pathname was already set e.g. by header_gnu_longname()
1527+
*/
15251528
header = (const struct archive_entry_header_ustar *)h;
1526-
if (archive_entry_copy_pathname_l(entry,
1529+
1530+
const char *existing_pathname = archive_entry_pathname(entry);
1531+
const wchar_t *existing_wcs_pathname = archive_entry_pathname_w(entry);
1532+
if ((existing_pathname == NULL || existing_pathname[0] == '\0')
1533+
&& (existing_wcs_pathname == NULL || existing_wcs_pathname[0] == '\0') &&
1534+
archive_entry_copy_pathname_l(entry,
15271535
header->name, sizeof(header->name), tar->sconv) != 0) {
15281536
err = set_conversion_failed_error(a, tar->sconv, "Pathname");
15291537
if (err == ARCHIVE_FATAL)

0 commit comments

Comments
 (0)