Coverage Report

Created: 2026-09-01 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libraw_fuzzer.cc
Line
Count
Source
1
/*  Copyright 2020 Google Inc.
2
3
Licensed under the Apache License, Version 2.0 (the "License");
4
you may not use this file except in compliance with the License.
5
You may obtain a copy of the License at
6
7
      http://www.apache.org/licenses/LICENSE-2.0
8
9
Unless required by applicable law or agreed to in writing, software
10
distributed under the License is distributed on an "AS IS" BASIS,
11
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
See the License for the specific language governing permissions and
13
limitations under the License.
14
*/
15
16
#include <stddef.h>
17
#include <stdint.h>
18
19
#include <string>
20
#include <fuzzer/FuzzedDataProvider.h>
21
22
#include <libraw.h>
23
24
enum InterpolationOptions {
25
  Linear = 0,
26
  Vng = 1, 
27
  Ppg = 2,
28
  Ahd = 3,
29
  Dcb = 4,
30
  Dht = 11,
31
  AhdModified = 12
32
};
33
static const InterpolationOptions options[] = {Linear, Vng, Ppg, Ahd, Dcb, Dht, AhdModified};
34
35
98.1k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
36
  // Input less than 15mb
37
98.1k
  if (size > 15000000) {
38
0
    return 0;
39
0
  }
40
41
98.1k
  FuzzedDataProvider fdp(data, size);
42
43
98.1k
  LibRaw lib_raw;
44
98.1k
  lib_raw.imgdata.rawparams.max_raw_memory_mb = 300;
45
46
490k
  for(int i =0; i < 4; i++)
47
392k
    lib_raw.output_params_ptr()->aber[i] = fdp.ConsumeFloatingPoint<double>();
48
490k
  for(int i =0; i < 4; i++)
49
392k
    lib_raw.output_params_ptr()->user_mul[i] = fdp.ConsumeFloatingPoint<float>();
50
294k
  for(int i =0; i < 2; i++)
51
196k
    lib_raw.output_params_ptr()->gamm[i] = fdp.ConsumeFloatingPoint<double>();
52
98.1k
  lib_raw.output_params_ptr()->bright = fdp.ConsumeFloatingPoint<float>();
53
98.1k
  lib_raw.output_params_ptr()->threshold = fdp.ConsumeFloatingPoint<float>();
54
98.1k
  lib_raw.output_params_ptr()->use_auto_wb = fdp.ConsumeIntegral<int>();
55
98.1k
  lib_raw.output_params_ptr()->output_color = fdp.ConsumeIntegralInRange<int>(0, 6);
56
98.1k
  lib_raw.output_params_ptr()->user_flip = fdp.ConsumeIntegralInRange<int>(0, 7);
57
98.1k
  lib_raw.output_params_ptr()->user_black = fdp.ConsumeIntegral<int>();
58
98.1k
  lib_raw.output_params_ptr()->user_sat = fdp.ConsumeIntegral<int>();
59
98.1k
  lib_raw.output_params_ptr()->auto_bright_thr = fdp.ConsumeFloatingPoint<float>();
60
98.1k
  lib_raw.output_params_ptr()->adjust_maximum_thr = fdp.ConsumeFloatingPointInRange<float>(0.f, 1.f);
61
98.1k
  lib_raw.output_params_ptr()->fbdd_noiserd = fdp.ConsumeIntegralInRange<int>(0, 5);
62
63
98.1k
  std::vector<char> payload = fdp.ConsumeRemainingBytes<char>();
64
98.1k
  int result = lib_raw.open_buffer(payload.data(), payload.size());
65
98.1k
  if (result != LIBRAW_SUCCESS) {
66
72.7k
    return 0;
67
72.7k
  }
68
69
25.4k
  result = lib_raw.unpack();
70
25.4k
  if (result != LIBRAW_SUCCESS) {
71
13.0k
    return 0;
72
13.0k
  }
73
74
12.4k
  result = lib_raw.unpack_thumb();
75
12.4k
  if (result != LIBRAW_SUCCESS) {
76
3.85k
    return 0;
77
3.85k
  }
78
79
8.55k
  result = lib_raw.raw2image();
80
8.55k
  if (result != LIBRAW_SUCCESS) {
81
816
    return 0;
82
816
  }
83
7.73k
  lib_raw.free_image();
84
85
56.2k
  for (int i = 0; i < sizeof(options)/sizeof(*options); i++) {
86
49.5k
    lib_raw.output_params_ptr()->user_qual = static_cast<int>(options[i]);
87
88
49.5k
    result = lib_raw.dcraw_process();
89
49.5k
    if (result != LIBRAW_SUCCESS) {
90
1.06k
      return 0;
91
1.06k
    }
92
49.5k
  }
93
94
6.67k
  return 0;
95
7.73k
}