Coverage Report

Created: 2025-06-24 07:01

/src/gstoraster_ps_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
#include "gs_fuzzlib.h"
13
14
/* Returns 1 if the data has a PDF header and 0 otherwise */
15
8.66k
static int is_pdf(const uint8_t *data, size_t size) {
16
  /* Two bytes are needed for the check */
17
8.66k
        if (size < 2) {
18
34
                return 0;
19
34
        }
20
21
        /* Check for "%P" tag. */
22
8.63k
        if (data[0] == 0x25 || data[1] == 0x50) {
23
2
                return 1;
24
2
        }
25
8.62k
        return 0;
26
8.63k
}
27
28
29
8.66k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
30
  /* Avoid PDF files */
31
8.66k
  if (size == 0 || is_pdf(data, size)) {
32
2
    return 0;
33
2
  }
34
35
  /* 
36
   * Modulo the possibilities: https://github.com/ArtifexSoftware/ghostpdl/blob/8c97d5adce0040ac38a1fb4d7954499c65f582ff/cups/libs/cups/raster.h#L102
37
     This enables the fuzzer to explore all color schemes
38
   */
39
8.66k
  int color_scheme = ((int)data[0] % 63);
40
8.66k
  data++;
41
8.66k
  size--;
42
43
8.66k
  gs_to_raster_fuzz(data, size, color_scheme);
44
8.66k
  return 0;
45
8.66k
}