summaryrefslogtreecommitdiff
path: root/fuzzer/dng_parser_fuzzer.cpp
blob: 84db0f34b8995afbb407ab01e5e3ebf2169e54f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stddef.h>
#include <stdint.h>

#include "dng_exceptions.h"
#include "dng_host.h"
#include "dng_info.h"
#include "dng_memory_stream.h"
#include "dng_negative.h"


extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  dng_host host;
  dng_memory_stream stream(host.Allocator());

  stream.Put(data, size);
  stream.SetReadPosition(0);

  std::unique_ptr<dng_negative> negative(host.Make_dng_negative());

  try {
    dng_info info;
    info.Parse(host, stream);
    info.PostParse(host);

    if (info.IsValidDNG()) {
      negative->Parse(host, stream, info);
      negative->PostParse(host, stream, info);
      negative->ReadStage1Image(host, stream, info);
    }
  } catch (dng_exception &e) {
    // dng_sdk throws C++ exceptions on errors
    // catch them here to prevent libFuzzer from crashing.
  }

  return 0;
}