From: Tobias Stoeckmann Date: Sat, 30 May 2026 19:09:28 +0000 (+0200) Subject: cpio: Improve afio header detection X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46a1f02675af339ed3a89b54afef6c1ffd2e0803;p=thirdparty%2Flibarchive.git cpio: Improve afio header detection Do not assume that enough bytes will be provided by filter if not explicitly requested. The requested size is 76, but some checks expect 116 bytes. If these were not supplied by filter, th afio header detection erroneously skips headers which otherwise could be found. Signed-off-by: Tobias Stoeckmann --- diff --git a/libarchive/archive_read_support_format_cpio.c b/libarchive/archive_read_support_format_cpio.c index 8f12b4126..1c4a66599 100644 --- a/libarchive/archive_read_support_format_cpio.c +++ b/libarchive/archive_read_support_format_cpio.c @@ -718,9 +718,19 @@ find_odc_header(struct archive_read *a) ssize_t bytes; for (;;) { - h = __archive_read_ahead(a, odc_header_size, &bytes); - if (h == NULL) - return (ARCHIVE_FATAL); + size_t header_size; + + header_size = afiol_header_size; + h = __archive_read_ahead(a, afiol_header_size, &bytes); + if (h == NULL) { + if (bytes >= odc_header_size) { + header_size = odc_header_size; + h = __archive_read_ahead(a, odc_header_size, + &bytes); + } + if (h == NULL) + return (ARCHIVE_FATAL); + } p = h; q = p + bytes; @@ -736,7 +746,7 @@ find_odc_header(struct archive_read *a) * Scan ahead until we find something that looks * like an odc header. */ - while (p + odc_header_size <= q) { + while (p + header_size <= q) { switch (p[5]) { case '7': if ((memcmp("070707", p, 6) == 0