-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1773 from kevinbackhouse/fuzz
Add fuzz target
- Loading branch information
Showing
10 changed files
with
122 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Builds and runs the fuzz target for a short amount of time. This is | ||
# mainly to protect the fuzz target from bitrot, but hopefully will | ||
# also help to quickly catch some bugs before the PR is merged. | ||
|
||
name: Linux-Ubuntu Quick Fuzz on PRs | ||
|
||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
Linux: | ||
name: 'Ubuntu 20.04 - clang/libFuzzer' | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: install dependencies | ||
run: sudo ./ci/install_dependencies.sh | ||
- name: build and compile | ||
run: | | ||
mkdir build && cd build | ||
cmake -DEXIV2_ENABLE_PNG=ON -DEXIV2_ENABLE_WEBREADY=ON -DEXIV2_ENABLE_CURL=ON -DEXIV2_ENABLE_BMFF=ON -DEXIV2_TEAM_WARNINGS_AS_ERRORS=ON -DCMAKE_CXX_COMPILER=$(which clang++) -DEXIV2_BUILD_FUZZ_TESTS=ON -DEXIV2_TEAM_USE_SANITIZERS=ON .. | ||
make -j $(nproc) | ||
- name: Fuzz | ||
run: | | ||
cd build | ||
mkdir corpus | ||
./bin/fuzz-read-print-write corpus ../test/data/ -jobs=$(nproc) -workers=$(nproc) -max_total_time=120 -max_len=4096 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
macro(fuzzer name) | ||
add_executable(${name} ${name}.cpp) | ||
set_target_properties(${name} | ||
PROPERTIES | ||
COMPILE_FLAGS "-fsanitize=fuzzer" | ||
LINK_FLAGS "-fsanitize=fuzzer") | ||
target_link_libraries(${name} | ||
PRIVATE | ||
exiv2lib | ||
) | ||
endmacro() | ||
|
||
fuzzer(fuzz-read-print-write) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <exiv2/exiv2.hpp> | ||
|
||
#include <iostream> | ||
#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); | ||
|
||
Exiv2::XmpParser::initialize(); | ||
::atexit(Exiv2::XmpParser::terminate); | ||
|
||
try { | ||
Exiv2::DataBuf data_copy(data, size); | ||
Exiv2::Image::UniquePtr image = | ||
Exiv2::ImageFactory::open(data_copy.pData_, size); | ||
assert(image.get() != 0); | ||
|
||
image->readMetadata(); | ||
image->exifData(); | ||
|
||
// Print to a std::ostringstream so that the fuzzer doesn't | ||
// produce lots of garbage on stdout. | ||
std::ostringstream buffer; | ||
image->printStructure(buffer, Exiv2::kpsNone); | ||
|
||
image->writeMetadata(); | ||
|
||
} catch(...) { | ||
// Exiv2 throws an exception if the metadata is invalid. | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters