Updates to make fuzzing work.

This commit is contained in:
Kevin Backhouse 2021-07-11 21:14:08 +01:00
parent b2cdf2a535
commit bf786f4cc6
No known key found for this signature in database
GPG Key ID: 9DD01852EE40366E
7 changed files with 23 additions and 14 deletions

View File

@ -92,7 +92,7 @@ if( EXIV2_BUILD_UNIT_TESTS )
add_subdirectory ( unitTests )
endif()
if( EXIV2_BUILD_FUZZ_TESTS)
if( EXIV2_BUILD_FUZZ_TESTS )
if ((NOT COMPILER_IS_CLANG) OR (NOT EXIV2_TEAM_USE_SANITIZERS))
message(FATAL_ERROR "You need to build with Clang and sanitizers for the fuzzers to work. "
"Use Clang and -DEXIV2_TEAM_USE_SANITIZERS=ON")

View File

@ -82,7 +82,9 @@ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN
set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address")
endif()
elseif( COMPILER_IS_CLANG )
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 )
if ( EXIV2_BUILD_FUZZ_TESTS )
set(SANITIZER_FLAGS "-fsanitize=fuzzer-no-link")
elseif ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 )
set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=all")
elseif ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.4 )
set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined")

View File

@ -11,4 +11,4 @@ macro(fuzzer name)
)
endmacro()
fuzzer(read-metadata)
fuzzer(read-metadata)

View File

@ -4,21 +4,26 @@
#include <iomanip>
#include <cassert>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t * Data, size_t Size) {
// Invalid files generate a lot of warnings, so switch off logging.
Exiv2::LogMsg::setLevel(Exiv2::LogMsg::mute);
extern "C" int LLVMFuzzerTestOneInput(const uint8_t * Data, size_t Size)
try {
Exiv2::XmpParser::initialize();
::atexit(Exiv2::XmpParser::terminate);
try {
Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open(Data, Size);
assert(image.get() != 0);
image->readMetadata();
Exiv2::ExifData &exifData = image->exifData();
if (exifData.empty()) {
return -1;
return -1;
}
} catch(...) {
// Exiv2 throws an exception if the metadata is invalid.
}
return 0;
}
catch (Exiv2::Error& e) {
return -1;
return 0;
}

View File

@ -474,13 +474,13 @@ namespace Exiv2 {
#endif
}
}
#ifndef SUPPRESS_WARNINGS
else {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "IPTC dataset " << IptcKey(dataSet, record)
<< " has invalid size " << sizeData << "; skipped.\n";
#endif
return 7;
}
#endif
pRead += sizeData;
}

View File

@ -181,7 +181,7 @@ namespace Exiv2 {
#endif
return -2;
}
#ifndef EXIV2_DEBUG_MESSAGES
#ifdef EXIV2_DEBUG_MESSAGES
if ( (dataSize & 1)
&& position + dataSize == static_cast<uint32_t>(sizePsData)) {
std::cerr << "Warning: "

View File

@ -1335,7 +1335,9 @@ namespace Exiv2 {
tc->setStart(p);
object->addChild(std::move(tc));
} else {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Unable to handle tag " << tag << ".\n";
#endif
}
p += 12;
}