Coverage Report

Created: 2025-02-19 06:30

/src/fuzz/pdf_surface_fuzzer.c
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2020 Google LLC
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
#include <cairo.h>
16
#include <cairo-pdf.h>
17
#include "fuzzer_temp_file.h"
18
19
const double width_in_inches = 3;
20
const double height_in_inches = 3;
21
const double width_in_points = width_in_inches * 72.0;
22
const double height_in_points = height_in_inches * 72.0;
23
24
651
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
25
651
    cairo_t *cr;
26
651
    cairo_surface_t *surface;
27
651
    cairo_status_t status;
28
29
651
    if (size == 0) {
30
0
        return 0;
31
0
    }
32
33
651
    char *tmpfile = fuzzer_get_tmpfile(data, size);
34
651
    surface = cairo_pdf_surface_create(tmpfile, width_in_points, height_in_points);
35
651
    status = cairo_surface_status(surface);
36
651
    if (status != CAIRO_STATUS_SUCCESS) {
37
0
        fuzzer_release_tmpfile(tmpfile);
38
0
        return 0;
39
0
    }
40
41
651
    char *buf = (char *) calloc(size + 1, sizeof(char));
42
651
    memcpy(buf, data, size);
43
651
    buf[size] = '\0';
44
45
651
    cairo_pdf_surface_set_metadata(surface, CAIRO_PDF_METADATA_TITLE, buf);
46
651
    cr = cairo_create(surface);
47
651
    cairo_tag_begin(cr, buf, NULL);
48
651
    cairo_tag_end(cr, buf);
49
50
651
    cairo_destroy(cr);
51
651
    cairo_surface_destroy(surface);
52
651
    free(buf);
53
651
    fuzzer_release_tmpfile(tmpfile);
54
651
    return 0;
55
651
}