Coverage Report

Created: 2026-02-14 06:48

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
16.9k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
36
  // Input less than 15mb
37
16.9k
  if (size > 15000000) {
38
0
    return 0;
39
0
  }
40
41
16.9k
  FuzzedDataProvider fdp(data, size);
42
16.9k
  LibRaw lib_raw;
43
44
84.8k
  for(int i =0; i < 4; i++)
45
67.8k
    lib_raw.output_params_ptr()->aber[i] = fdp.ConsumeFloatingPoint<double>();
46
84.8k
  for(int i =0; i < 4; i++)
47
67.8k
    lib_raw.output_params_ptr()->user_mul[i] = fdp.ConsumeFloatingPoint<float>();
48
50.8k
  for(int i =0; i < 2; i++)
49
33.9k
    lib_raw.output_params_ptr()->gamm[i] = fdp.ConsumeFloatingPoint<double>();
50
16.9k
  lib_raw.output_params_ptr()->bright = fdp.ConsumeFloatingPoint<float>();
51
16.9k
  lib_raw.output_params_ptr()->threshold = fdp.ConsumeFloatingPoint<float>();
52
16.9k
  lib_raw.output_params_ptr()->use_auto_wb = fdp.ConsumeIntegral<int>();
53
16.9k
  lib_raw.output_params_ptr()->output_color = fdp.ConsumeIntegralInRange<int>(0, 6);
54
16.9k
  lib_raw.output_params_ptr()->user_flip = fdp.ConsumeIntegralInRange<int>(0, 7);
55
16.9k
  lib_raw.output_params_ptr()->user_black = fdp.ConsumeIntegral<int>();
56
16.9k
  lib_raw.output_params_ptr()->user_sat = fdp.ConsumeIntegral<int>();
57
16.9k
  lib_raw.output_params_ptr()->auto_bright_thr = fdp.ConsumeFloatingPoint<float>();
58
16.9k
  lib_raw.output_params_ptr()->adjust_maximum_thr = fdp.ConsumeFloatingPointInRange<float>(0.f, 1.f);
59
16.9k
  lib_raw.output_params_ptr()->fbdd_noiserd = fdp.ConsumeIntegralInRange<int>(0, 5);
60
61
16.9k
  std::vector<char> payload = fdp.ConsumeRemainingBytes<char>();
62
16.9k
  int result = lib_raw.open_buffer(payload.data(), payload.size());
63
16.9k
  if (result != LIBRAW_SUCCESS) {
64
12.8k
    return 0;
65
12.8k
  }
66
67
4.14k
  result = lib_raw.unpack();
68
4.14k
  if (result != LIBRAW_SUCCESS) {
69
2.25k
    return 0;
70
2.25k
  }
71
72
1.89k
  result = lib_raw.unpack_thumb();
73
1.89k
  if (result != LIBRAW_SUCCESS) {
74
682
    return 0;
75
682
  }
76
77
1.20k
  result = lib_raw.raw2image();
78
1.20k
  if (result != LIBRAW_SUCCESS) {
79
122
    return 0;
80
122
  }
81
1.08k
  lib_raw.free_image();
82
83
7.53k
  for (int i = 0; i < sizeof(options)/sizeof(*options); i++) {
84
6.65k
    lib_raw.output_params_ptr()->user_qual = static_cast<int>(options[i]);
85
86
6.65k
    result = lib_raw.dcraw_process();
87
6.65k
    if (result != LIBRAW_SUCCESS) {
88
199
      return 0;
89
199
    }
90
6.65k
  }
91
92
887
  return 0;
93
1.08k
}