/src/dng_sdk/fuzzer/dng_parser_fuzzer.cpp
Line | Count | Source |
1 | | #include <stddef.h> |
2 | | #include <stdint.h> |
3 | | |
4 | | #include "dng_exceptions.h" |
5 | | #include "dng_host.h" |
6 | | #include "dng_info.h" |
7 | | #include "dng_memory_stream.h" |
8 | | #include "dng_negative.h" |
9 | | |
10 | | |
11 | 4.91k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
12 | 4.91k | dng_host host; |
13 | 4.91k | dng_memory_stream stream(host.Allocator()); |
14 | | |
15 | 4.91k | stream.Put(data, size); |
16 | 4.91k | stream.SetReadPosition(0); |
17 | | |
18 | 4.91k | std::unique_ptr<dng_negative> negative(host.Make_dng_negative()); |
19 | | |
20 | 4.91k | try { |
21 | 4.91k | dng_info info; |
22 | 4.91k | info.Parse(host, stream); |
23 | 4.91k | info.PostParse(host); |
24 | | |
25 | 4.91k | if (info.IsValidDNG()) { |
26 | 3.90k | negative->Parse(host, stream, info); |
27 | 3.90k | negative->PostParse(host, stream, info); |
28 | 3.90k | negative->ReadStage1Image(host, stream, info); |
29 | 3.90k | } |
30 | 4.91k | } catch (dng_exception &e) { |
31 | | // dng_sdk throws C++ exceptions on errors |
32 | | // catch them here to prevent libFuzzer from crashing. |
33 | 4.28k | } |
34 | | |
35 | 4.91k | return 0; |
36 | 4.91k | } |