Coverage Report

Created: 2025-12-31 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
7.82k
static int is_pdf(const uint8_t *data, size_t size) {
16
  /* Two bytes are needed for the check */
17
7.82k
        if (size < 2) {
18
43
                return 0;
19
43
        }
20
21
        /* Check for "%P" tag. */
22
7.78k
        if (data[0] == 0x25 || data[1] == 0x50) {
23
2
                return 1;
24
2
        }
25
7.78k
        return 0;
26
7.78k
}
27
28
29
7.82k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
30
  /* Avoid PDF files */
31
7.82k
  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
7.82k
  int color_scheme = ((int)data[0] % 63);
40
7.82k
  data++;
41
7.82k
  size--;
42
43
7.82k
  gs_to_raster_fuzz(data, size, color_scheme);
44
7.82k
  return 0;
45
7.82k
}