/src/gstoraster_pdf_fuzzer.cc
Line | Count | Source |
1 | | /* Copyright 2022 Google LLC |
2 | | Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | you may not use this file except in compliance with the License. |
4 | | You may obtain a copy of the License at |
5 | | http://www.apache.org/licenses/LICENSE-2.0 |
6 | | Unless required by applicable law or agreed to in writing, software |
7 | | distributed under the License is distributed on an "AS IS" BASIS, |
8 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | See the License for the specific language governing permissions and |
10 | | limitations under the License. |
11 | | */ |
12 | | |
13 | | #include "gs_fuzzlib.h" |
14 | | |
15 | | // Returns 1 if this has a valid PDF header and 0 otherwise |
16 | 9.21k | static int quick_check_pdf(const uint8_t *data, size_t size) { |
17 | | // PDF checks. Exit early if we don't have a valid PDF signature. |
18 | 9.21k | if (size < 5) { |
19 | 4 | return 0; |
20 | 4 | } |
21 | | |
22 | | // Check PDF tag. We do this because we want to use seeds |
23 | 9.21k | if (data[0] != 0x25 || data[1] != 0x50 || data[2] != 0x44 || data[3] != 0x46 || data[4] != 0x2d) { |
24 | 8 | return 0; |
25 | 8 | } |
26 | 9.20k | return 1; |
27 | 9.21k | } |
28 | | |
29 | 9.21k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
30 | 9.21k | if (quick_check_pdf(data, size) != 1) { |
31 | 12 | return 0; |
32 | 12 | } |
33 | | |
34 | | /* Tests using RGB color scheme */ |
35 | 9.20k | gs_to_raster_fuzz(data, size, 1); |
36 | 9.20k | return 0; |
37 | 9.21k | } |