From: Tobias Stoeckmann Date: Tue, 19 May 2026 19:16:24 +0000 (+0200) Subject: tar: Fix empty wide character string handling X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=843b3baea18d20cace458c4a3d1bbf2fa6f45018;p=thirdparty%2Flibarchive.git tar: Fix empty wide character string handling Apply the same fix as done in commit c246ec5d058a3f70a2d3fb765f92fe9db77b25df for non-wide character strings. Without this, empty strings lead to out of boundary read accesses. Resolves #3046. Signed-off-by: Tobias Stoeckmann --- diff --git a/libarchive/archive_write_set_format_gnutar.c b/libarchive/archive_write_set_format_gnutar.c index b67007a63..f2ba4a0db 100644 --- a/libarchive/archive_write_set_format_gnutar.c +++ b/libarchive/archive_write_set_format_gnutar.c @@ -321,7 +321,8 @@ archive_write_gnutar_header(struct archive_write *a, const wchar_t *wp; wp = archive_entry_pathname_w(entry); - if (wp != NULL && wp[wcslen(wp) -1] != L'/') { + if (wp != NULL && wp[0] != L'\0' && + wp[wcslen(wp) - 1] != L'/') { struct archive_wstring ws; archive_string_init(&ws); diff --git a/libarchive/archive_write_set_format_pax.c b/libarchive/archive_write_set_format_pax.c index f3589d685..debd2c6bf 100644 --- a/libarchive/archive_write_set_format_pax.c +++ b/libarchive/archive_write_set_format_pax.c @@ -676,7 +676,8 @@ archive_write_pax_header(struct archive_write *a, const wchar_t *wp; wp = archive_entry_pathname_w(entry_original); - if (wp != NULL && wp[wcslen(wp) -1] != L'/') { + if (wp != NULL && wp[0] != L'\0' && + wp[wcslen(wp) - 1] != L'/') { struct archive_wstring ws; archive_string_init(&ws); diff --git a/libarchive/archive_write_set_format_ustar.c b/libarchive/archive_write_set_format_ustar.c index 97724c158..e84152ea1 100644 --- a/libarchive/archive_write_set_format_ustar.c +++ b/libarchive/archive_write_set_format_ustar.c @@ -281,7 +281,8 @@ archive_write_ustar_header(struct archive_write *a, struct archive_entry *entry) const wchar_t *wp; wp = archive_entry_pathname_w(entry); - if (wp != NULL && wp[wcslen(wp) -1] != L'/') { + if (wp != NULL && wp[0] != L'\0' && + wp[wcslen(wp) - 1] != L'/') { struct archive_wstring ws; archive_string_init(&ws); diff --git a/libarchive/archive_write_set_format_v7tar.c b/libarchive/archive_write_set_format_v7tar.c index 37ba73a13..91c5e8e42 100644 --- a/libarchive/archive_write_set_format_v7tar.c +++ b/libarchive/archive_write_set_format_v7tar.c @@ -259,7 +259,8 @@ archive_write_v7tar_header(struct archive_write *a, struct archive_entry *entry) const wchar_t *wp; wp = archive_entry_pathname_w(entry); - if (wp != NULL && wp[wcslen(wp) -1] != L'/') { + if (wp != NULL && wp[0] != L'\0' && + wp[wcslen(wp) - 1] != L'/') { struct archive_wstring ws; archive_string_init(&ws);