]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
ar: Simplify ar_parse_common_header usage
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 28 Jun 2026 09:40:55 +0000 (11:40 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 29 Jun 2026 15:12:37 +0000 (17:12 +0200)
The function ar_parse_common_header can be called at exactly one
position in _ar_read_header, since it parses common information.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libarchive/archive_read_support_format_ar.c

index fc786dfb24e2eb3d4cf5e141af03391e2a5092e9..050c2e5fc62028347ff363f872c92ed7b9a5927c 100644 (file)
@@ -91,7 +91,7 @@ static int    archive_read_format_ar_read_header(struct archive_read *a,
 static uint64_t        ar_atol8(const char *p, size_t char_cnt);
 static uint64_t        ar_atol10(const char *p, size_t char_cnt);
 static int     ar_parse_gnu_filename_table(struct archive_read *a);
-static int     ar_parse_common_header(struct ar *ar, struct archive_entry *,
+static void    ar_parse_common_header(struct ar *ar, struct archive_entry *,
                    const char *h);
 
 int
@@ -172,7 +172,6 @@ _ar_read_header(struct archive_read *a, struct archive_entry *entry,
        size_t bsd_name_length, entry_size;
        char *p, *st;
        const void *b;
-       int r;
 
        /* Verify the magic signature on the file header. */
        if (strncmp(h + AR_fmag_offset, "`\n", 2) != 0) {
@@ -247,13 +246,17 @@ _ar_read_header(struct archive_read *a, struct archive_entry *entry,
                return (ARCHIVE_FATAL);
        }
 
+       /*
+        * Parse the time, owner, mode, size fields.
+        * This must come before any call to _read_ahead.
+        */
+       ar_parse_common_header(ar, entry, h);
+
        /*
         * '//' is the GNU filename table.
         * Later entries can refer to names in this table.
         */
        if (strcmp(filename, "//") == 0) {
-               /* This must come before any call to _read_ahead. */
-               ar_parse_common_header(ar, entry, h);
                archive_entry_copy_pathname(entry, filename);
                archive_entry_set_filetype(entry, AE_IFREG);
                /* Get the size of the filename table. */
@@ -318,14 +321,11 @@ _ar_read_header(struct archive_read *a, struct archive_entry *entry,
                        archive_set_error(&a->archive, EINVAL,
                            "Can't find long filename for GNU/SVR4 archive entry");
                        archive_entry_copy_pathname(entry, filename);
-                       /* Parse the time, owner, mode, size fields. */
-                       ar_parse_common_header(ar, entry, h);
                        return (ARCHIVE_FATAL);
                }
 
                archive_entry_copy_pathname(entry, &ar->strtab[(size_t)number]);
-               /* Parse the time, owner, mode, size fields. */
-               return (ar_parse_common_header(ar, entry, h));
+               return (ARCHIVE_OK);
        }
 
        /*
@@ -334,10 +334,6 @@ _ar_read_header(struct archive_read *a, struct archive_entry *entry,
         * the filename to the file contents.
         */
        if (strncmp(filename, "#1/", 3) == 0) {
-               /* Parse the time, owner, mode, size fields. */
-               /* This must occur before _read_ahead is called again. */
-               ar_parse_common_header(ar, entry, h);
-
                /* Parse the size of the name, adjust the file size. */
                number = ar_atol10(h + AR_name_offset + 3, AR_name_size - 3);
                /* Sanity check the filename length:
@@ -391,11 +387,9 @@ _ar_read_header(struct archive_read *a, struct archive_entry *entry,
         */
        if (strcmp(filename, "/") == 0 || strcmp(filename, "/SYM64/") == 0) {
                archive_entry_copy_pathname(entry, filename);
-               /* Parse the time, owner, mode, size fields. */
-               r = ar_parse_common_header(ar, entry, h);
                /* Force the file type to a regular file. */
                archive_entry_set_filetype(entry, AE_IFREG);
-               return (r);
+               return (ARCHIVE_OK);
        }
 
        /*
@@ -403,8 +397,7 @@ _ar_read_header(struct archive_read *a, struct archive_entry *entry,
         */
        if (strcmp(filename, "__.SYMDEF") == 0) {
                archive_entry_copy_pathname(entry, filename);
-               /* Parse the time, owner, mode, size fields. */
-               return (ar_parse_common_header(ar, entry, h));
+               return (ARCHIVE_OK);
        }
 
        /*
@@ -413,7 +406,7 @@ _ar_read_header(struct archive_read *a, struct archive_entry *entry,
         * on our current knowledge of the format.
         */
        archive_entry_copy_pathname(entry, filename);
-       return (ar_parse_common_header(ar, entry, h));
+       return (ARCHIVE_OK);
 }
 
 static int
@@ -452,7 +445,7 @@ archive_read_format_ar_read_header(struct archive_read *a,
 }
 
 
-static int
+static void
 ar_parse_common_header(struct ar *ar, struct archive_entry *entry,
     const char *h)
 {
@@ -474,7 +467,6 @@ ar_parse_common_header(struct ar *ar, struct archive_entry *entry,
        ar->entry_padding = n % 2;
        archive_entry_set_size(entry, n);
        ar->entry_bytes_remaining = n;
-       return (ARCHIVE_OK);
 }
 
 static int