Line | Count | Source (jump to first uncovered line) |
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 | 33.0k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
36 | | // Input less than 15mb |
37 | 33.0k | if (size > 15000000) { |
38 | 0 | return 0; |
39 | 0 | } |
40 | | |
41 | 33.0k | FuzzedDataProvider fdp(data, size); |
42 | 33.0k | LibRaw lib_raw; |
43 | | |
44 | 165k | for(int i =0; i < 4; i++) |
45 | 132k | lib_raw.output_params_ptr()->aber[i] = fdp.ConsumeFloatingPoint<double>(); |
46 | 165k | for(int i =0; i < 4; i++) |
47 | 132k | lib_raw.output_params_ptr()->user_mul[i] = fdp.ConsumeFloatingPoint<float>(); |
48 | 99.1k | for(int i =0; i < 2; i++) |
49 | 66.0k | lib_raw.output_params_ptr()->gamm[i] = fdp.ConsumeFloatingPoint<double>(); |
50 | 33.0k | lib_raw.output_params_ptr()->bright = fdp.ConsumeFloatingPoint<float>(); |
51 | 33.0k | lib_raw.output_params_ptr()->threshold = fdp.ConsumeFloatingPoint<float>(); |
52 | 33.0k | lib_raw.output_params_ptr()->use_auto_wb = fdp.ConsumeIntegral<int>(); |
53 | 33.0k | lib_raw.output_params_ptr()->output_color = fdp.ConsumeIntegralInRange<int>(0, 6); |
54 | 33.0k | lib_raw.output_params_ptr()->user_flip = fdp.ConsumeIntegralInRange<int>(0, 7); |
55 | 33.0k | lib_raw.output_params_ptr()->user_black = fdp.ConsumeIntegral<int>(); |
56 | 33.0k | lib_raw.output_params_ptr()->user_sat = fdp.ConsumeIntegral<int>(); |
57 | 33.0k | lib_raw.output_params_ptr()->auto_bright_thr = fdp.ConsumeFloatingPoint<float>(); |
58 | 33.0k | lib_raw.output_params_ptr()->adjust_maximum_thr = fdp.ConsumeFloatingPointInRange<float>(0.f, 1.f); |
59 | 33.0k | lib_raw.output_params_ptr()->fbdd_noiserd = fdp.ConsumeIntegralInRange<int>(0, 5); |
60 | | |
61 | 33.0k | std::vector<char> payload = fdp.ConsumeRemainingBytes<char>(); |
62 | 33.0k | int result = lib_raw.open_buffer(payload.data(), payload.size()); |
63 | 33.0k | if (result != LIBRAW_SUCCESS) { |
64 | 24.5k | return 0; |
65 | 24.5k | } |
66 | | |
67 | 8.49k | result = lib_raw.unpack(); |
68 | 8.49k | if (result != LIBRAW_SUCCESS) { |
69 | 4.33k | return 0; |
70 | 4.33k | } |
71 | | |
72 | 4.16k | result = lib_raw.unpack_thumb(); |
73 | 4.16k | if (result != LIBRAW_SUCCESS) { |
74 | 1.33k | return 0; |
75 | 1.33k | } |
76 | | |
77 | 2.82k | result = lib_raw.raw2image(); |
78 | 2.82k | if (result != LIBRAW_SUCCESS) { |
79 | 226 | return 0; |
80 | 226 | } |
81 | 2.59k | lib_raw.free_image(); |
82 | | |
83 | 18.4k | for (int i = 0; i < sizeof(options)/sizeof(*options); i++) { |
84 | 16.3k | lib_raw.output_params_ptr()->user_qual = static_cast<int>(options[i]); |
85 | | |
86 | 16.3k | result = lib_raw.dcraw_process(); |
87 | 16.3k | if (result != LIBRAW_SUCCESS) { |
88 | 429 | return 0; |
89 | 429 | } |
90 | 16.3k | } |
91 | | |
92 | 2.16k | return 0; |
93 | 2.59k | } |