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
21 #include <libraw.h>
22
23 enum InterpolationOptions {
24 Linear = 0,
25 Vng = 1,
26 Ppg = 2,
27 Ahd = 3,
28 Dcb = 4,
29 Dht = 11,
30 AhdModified = 12
31 };
32
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)33 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
34 // Input less than 15mb
35 if (size > 15000000) {
36 return 0;
37 }
38
39 LibRaw lib_raw;
40
41 int result = lib_raw.open_buffer(
42 const_cast<char*>(reinterpret_cast<const char*>(data)), size);
43 if (result != LIBRAW_SUCCESS) {
44 return 0;
45 }
46
47 result = lib_raw.unpack();
48 if (result != LIBRAW_SUCCESS) {
49 return 0;
50 }
51
52 InterpolationOptions options[] = {Linear, Vng, Ppg, Ahd, Dcb, Dht, AhdModified};
53
54 for (int i = 0; i < sizeof(options)/sizeof(*options); i++) {
55 lib_raw.output_params_ptr()->user_qual = static_cast<int>(options[i]);
56
57 result = lib_raw.dcraw_process();
58 if (result != LIBRAW_SUCCESS) {
59 return 0;
60 }
61 }
62
63 return 0;
64 }
65