From 890c4696c437709c7a5da1960ae16cfb33f9b88c Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 6 Jan 2025 22:14:56 +0100 Subject: [PATCH] fuzzers: add a fuzzer for LIBERTIFF driver Fixes #11523 --- fuzzers/CMakeLists.txt | 10 ++++++++++ fuzzers/build_google_oss_fuzzers.sh | 2 ++ fuzzers/gdal_fuzzer.cpp | 10 +++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/fuzzers/CMakeLists.txt b/fuzzers/CMakeLists.txt index 5cf1b6dc73bf..22347958d5d9 100644 --- a/fuzzers/CMakeLists.txt +++ b/fuzzers/CMakeLists.txt @@ -124,6 +124,16 @@ build_gdal_specialized_fuzzer(gdal_sdts GDALRegister_SDTS "/vsimem/test.tar" "/v build_gdal_specialized_fuzzer(gdal_vrt GDALAllRegister "/vsimem/test.tar" "/vsitar//vsimem/test.tar/test.vrt") build_gdal_specialized_fuzzer(ers GDALRegister_ERS "/vsimem/test.tar" "/vsitar//vsimem/test.tar/test.ers") +build_fuzzer( + NAME + libertiff_fuzzer + SOURCES + gdal_fuzzer.cpp + DEFINITIONS + -DREGISTER_FUNC=GDALRegister_LIBERTIFF + -DDRIVER_NAME="LIBERTIFF" +) + build_fuzzer( NAME gdal_filesystem_fuzzer diff --git a/fuzzers/build_google_oss_fuzzers.sh b/fuzzers/build_google_oss_fuzzers.sh index ad0b2c2a863c..3035cae6f5db 100755 --- a/fuzzers/build_google_oss_fuzzers.sh +++ b/fuzzers/build_google_oss_fuzzers.sh @@ -69,6 +69,8 @@ build_gdal_specialized_fuzzer() build_fuzzer gtiff_mmap $(dirname $0)/gdal_fuzzer.cpp -DREGISTER_FUNC=GDALRegister_GTiff -DGTIFF_USE_MMAP +build_fuzzer libertiff $(dirname $0)/gdal_fuzzer.cpp -DREGISTER_FUNC=GDALRegister_LIBERTIFF -DDRIVER_NAME="\"LIBERTIFF\"" + fuzzerFiles="$(dirname $0)/*.cpp" for F in $fuzzerFiles; do if test $F != "$(dirname $0)/fuzzingengine.cpp"; then diff --git a/fuzzers/gdal_fuzzer.cpp b/fuzzers/gdal_fuzzer.cpp index 495862edd992..ef66a37c8c17 100644 --- a/fuzzers/gdal_fuzzer.cpp +++ b/fuzzers/gdal_fuzzer.cpp @@ -213,7 +213,15 @@ int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) #else const char *pszGDALFilename = GDAL_FILENAME; #endif - GDALDatasetH hDS = GDALOpen(pszGDALFilename, GA_ReadOnly); + +#ifdef DRIVER_NAME + const char *const apszAllowedDrivers[] = {DRIVER_NAME, nullptr}; +#else + const char *const *apszAllowedDrivers = nullptr; +#endif + + GDALDatasetH hDS = GDALOpenEx(pszGDALFilename, GDAL_OF_RASTER, + apszAllowedDrivers, nullptr, nullptr); if (hDS) { const int nTotalBands = GDALGetRasterCount(hDS);