]> git.ipfire.org Git - thirdparty/libarchive.git/commit
RAR5 reader: fix multiple issues in extra field parsing function 2713/head
authorGrzegorz Antoniak <ga@anadoxin.org>
Fri, 1 Aug 2025 20:02:30 +0000 (22:02 +0200)
committerGrzegorz Antoniak <ga@anadoxin.org>
Sun, 3 Aug 2025 13:28:58 +0000 (15:28 +0200)
commit0ff100c8d32632d2564615114207a474cea8abe5
tree77941672e9813e59cd0c1110fcaeb4c46b8f4639
parent6062470cbcf5ff76535b6f161ce9cc9f4c6f56c0
RAR5 reader: fix multiple issues in extra field parsing function

This commit fixes multiple issues found in the function that parses
extra fields found in the "file"/"service" blocks.

1. In case the file declares just one extra field, which is an
   unsupported field, the function returns ARCHIVE_FATAL.

   The commit fixes this so this case is allowed, and the unsupported
   extra field is skipped. The commit also introduces a test for this
   case.

2. Current parsing method of extra fields can report parsing errors in
   case the file is malformed. The problem is that next iteration of
   parsing, which is meant to process the next extra field (if any),
   overwrites the result of the previous iteration, even if previous
   iteration has reported parsing error. A successful parse can be
   returned in this case, leading to undefined behavior.

   This commit changes the behavior to fail the parsing function early.
   Also a test file is introduced for this case.

3. In case the file declares only the EX_CRYPT extra field, current
   function simply returns ARCHIVE_FATAL, preventing the caller from
   setting the proper error string. This results in libarchive returning
   an ARCHIVE_FATAL without any error messages set. The PR #2096 (commit
   adee36b00) was specifically created to provide error strings in case
   EX_CRYPT attribute was encountered, but current behavior contradicts
   this case.

   The commit changes the behavior so that ARCHIVE_OK is returned by the
   extra field parsing function in only EX_CRYPT is encountered, so that
   the caller header reading function can properly return ARCHIVE_FATAL
   to the caller, at the same time setting a proper error string. A test
   file is also provided for this case.

This PR should fix issue #2711.
Makefile.am
libarchive/archive_read_support_format_rar5.c
libarchive/test/test_read_format_rar5.c
libarchive/test/test_read_format_rar5_invalid_hash_valid_htime_exfld.rar.uu [new file with mode: 0644]
libarchive/test/test_read_format_rar5_only_crypt_exfld.rar.uu [new file with mode: 0644]
libarchive/test/test_read_format_rar5_unsupported_exfld.rar.uu [new file with mode: 0644]