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
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)11 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
12 dng_host host;
13 dng_memory_stream stream(host.Allocator());
14
15 stream.Put(data, size);
16 stream.SetReadPosition(0);
17
18 std::unique_ptr<dng_negative> negative(host.Make_dng_negative());
19
20 try {
21 dng_info info;
22 info.Parse(host, stream);
23 info.PostParse(host);
24
25 if (info.IsValidDNG()) {
26 negative->Parse(host, stream, info);
27 negative->PostParse(host, stream, info);
28 negative->ReadStage1Image(host, stream, info);
29 }
30 } catch (dng_exception &e) {
31 // dng_sdk throws C++ exceptions on errors
32 // catch them here to prevent libFuzzer from crashing.
33 }
34
35 return 0;
36 }
37