]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
cpio: Improve afio header detection 3095/head
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 30 May 2026 19:09:28 +0000 (21:09 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 31 May 2026 09:07:43 +0000 (11:07 +0200)
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 <tobias@stoeckmann.org>
libarchive/archive_read_support_format_cpio.c

index 8f12b412679dfd700c8fa7076936d5acc49d3310..1c4a66599760a025a8510e5afcf6adae0841c86b 100644 (file)
@@ -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