]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
7-Zip: Set error message when reading ahead fails 3067/head
authorFrançois Degros <fdegros@chromium.org>
Mon, 25 May 2026 05:27:37 +0000 (15:27 +1000)
committerDustin L. Howett <dustin@howett.net>
Tue, 26 May 2026 22:15:47 +0000 (17:15 -0500)
Nice to have more explicit error messages.

libarchive/archive_read_support_format_7zip.c

index 2f1ab7d75b782da20eb0f92617a9f9e30818d545..5995618730cc18ee45fa3497a87d4b9f3f812887 100644 (file)
@@ -537,8 +537,11 @@ get_data_offset(struct archive_read *a, int64_t *data_offset)
        int64_t offset, sfx_offset;
        int r, window;
 
-       if ((p = __archive_read_ahead(a, 6, NULL)) == NULL)
-               goto fail;
+       if ((p = __archive_read_ahead(a, 6, NULL)) == NULL) {
+               archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+                   "Truncated 7-Zip file body");
+               return (ARCHIVE_FATAL);
+       }
 
        /* If first six bytes are the 7-Zip signature,
         * return the offset right now. */
@@ -3272,8 +3275,11 @@ slurp_central_directory(struct archive_read *a, struct _7zip *zip,
                archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Seek error");
                return (ARCHIVE_FATAL);
        }
-       if ((p = __archive_read_ahead(a, 32, &bytes_avail)) == NULL)
+       if ((p = __archive_read_ahead(a, 32, &bytes_avail)) == NULL) {
+               archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+                   "Truncated 7-Zip file header");
                return (ARCHIVE_FATAL);
+       }
 
        zip->seek_base = (uint64_t)data_offset + 32;