Coverage Report

Created: 2025-11-16 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fuzz/raster_fuzzer.c
Line
Count
Source
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
static cairo_surface_t *
20
acquire (cairo_pattern_t *pattern, void *closure,
21
       cairo_surface_t *target,
22
       const cairo_rectangle_int_t *extents)
23
0
{
24
0
    return cairo_image_surface_create_from_png(closure);
25
0
}
26
27
static void
28
release (cairo_pattern_t *pattern, void *closure, cairo_surface_t *surface)
29
0
{
30
0
    cairo_surface_destroy(surface);
31
0
}
32
33
5.22k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
34
5.22k
    cairo_t *cr;
35
5.22k
    cairo_surface_t *surface;
36
5.22k
    cairo_pattern_t *pattern;
37
5.22k
    cairo_content_t content;
38
5.22k
    cairo_status_t status;
39
5.22k
    int w, h;
40
41
5.22k
    char *tmpfile = fuzzer_get_tmpfile(data, size);
42
5.22k
    surface = cairo_image_surface_create_from_png(tmpfile);
43
5.22k
    status = cairo_surface_status (surface);
44
5.22k
    if (status != CAIRO_STATUS_SUCCESS) {
45
5.13k
        fuzzer_release_tmpfile(tmpfile);
46
5.13k
        return 0;
47
5.13k
    }
48
49
85
    cr = cairo_create(surface);
50
85
    content = cairo_surface_get_content(surface);
51
85
    w = cairo_image_surface_get_width(surface);
52
85
    h = cairo_image_surface_get_height(surface);
53
54
85
    char *buf = (char *) calloc(size + 1, sizeof(char));
55
85
    memcpy(buf, data, size);
56
85
    buf[size] = '\0';
57
58
85
    pattern = cairo_pattern_create_raster_source(buf, content, w, h);
59
85
    cairo_raster_source_pattern_set_acquire (pattern, acquire, release);
60
85
    cairo_set_source(cr, pattern);
61
85
    cairo_pdf_surface_set_page_label(surface, buf);
62
85
    cairo_pdf_surface_set_metadata(surface, CAIRO_PDF_METADATA_KEYWORDS, buf);
63
85
    cairo_paint(cr);
64
65
85
    cairo_destroy(cr);
66
85
    cairo_pattern_destroy(pattern);
67
85
    cairo_surface_destroy(surface);
68
85
    free(buf);
69
85
    fuzzer_release_tmpfile(tmpfile);
70
85
    return 0;
71
5.22k
}