]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fuzzing: Expose `DONT_FAIL_ON_CRC_ERROR` as a CMake option and honor it in the rar5...
authorMrmaxmeier <3913977+Mrmaxmeier@users.noreply.github.com>
Wed, 12 Jun 2024 18:57:20 +0000 (20:57 +0200)
committerGitHub <noreply@github.com>
Wed, 12 Jun 2024 18:57:20 +0000 (11:57 -0700)
Hey,

the fuzzing infrastructure over at OSSFuzz builds libarchive with the
CMake option `-DDONT_FAIL_ON_CRC_ERROR=1`.

https://github.com/google/oss-fuzz/blob/e4643b64b3af4932bff23bb87afdfbac2a301969/projects/libarchive/build.sh#L35
This, unfortunatly, does not do anything since it's never been defined
as an option.

Building the fuzzers with CRC checks disabled should improve fuzzing
efficacy a bunch.

Thanks!

CMakeLists.txt
libarchive/archive_read_support_format_rar5.c

index 3c86789c8b2be7c14b0e0bb9b69546f427f3135f..7bfaf4cfa7497c0d2a1d6490f69e0334eea215d0 100644 (file)
@@ -2173,6 +2173,11 @@ IF(APPLE)
   ADD_DEFINITIONS(-Wno-deprecated-declarations)
 ENDIF(APPLE)
 
+OPTION(DONT_FAIL_ON_CRC_ERROR "Ignore CRC errors during parsing (For fuzzing)" OFF)
+IF(DONT_FAIL_ON_CRC_ERROR)
+  ADD_DEFINITIONS(-DDONT_FAIL_ON_CRC_ERROR=1)
+ENDIF(DONT_FAIL_ON_CRC_ERROR)
+
 IF(ENABLE_TEST)
   ADD_CUSTOM_TARGET(run_all_tests)
 ENDIF(ENABLE_TEST)
index e06effe8b446f8bf6255b1bf8a1207d49cfd1c94..bd5a02179fb2e937c3d83d8e0aeeccda2e27f2c4 100644 (file)
@@ -2229,10 +2229,12 @@ static int process_base_block(struct archive_read* a,
        /* Verify the CRC32 of the header data. */
        computed_crc = (uint32_t) crc32(0, p, (int) hdr_size);
        if(computed_crc != hdr_crc) {
+#ifndef DONT_FAIL_ON_CRC_ERROR
                archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
                    "Header CRC error");
 
                return ARCHIVE_FATAL;
+#endif
        }
 
        /* If the checksum is OK, we proceed with parsing. */