Coverage Report

Created: 2026-04-01 06:39

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 "fuzzer_temp_file.h"
17
18
static cairo_surface_t *
19
acquire (cairo_pattern_t *pattern, void *closure,
20
       cairo_surface_t *target,
21
       const cairo_rectangle_int_t *extents)
22
61
{
23
61
    return cairo_image_surface_create_from_png(closure);
24
61
}
25
26
static void
27
release (cairo_pattern_t *pattern, void *closure, cairo_surface_t *surface)
28
0
{
29
0
    cairo_surface_destroy(surface);
30
0
}
31
32
6.13k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
33
6.13k
    cairo_t *cr;
34
6.13k
    cairo_surface_t *surface;
35
6.13k
    cairo_pattern_t *pattern;
36
6.13k
    cairo_content_t content;
37
6.13k
    cairo_status_t status;
38
6.13k
    int w, h;
39
40
6.13k
    char *tmpfile = fuzzer_get_tmpfile(data, size);
41
6.13k
    surface = cairo_image_surface_create_from_png(tmpfile);
42
6.13k
    status = cairo_surface_status (surface);
43
6.13k
    if (status != CAIRO_STATUS_SUCCESS) {
44
6.07k
        fuzzer_release_tmpfile(tmpfile);
45
6.07k
        return 0;
46
6.07k
    }
47
48
61
    cr = cairo_create(surface);
49
61
    content = cairo_surface_get_content(surface);
50
61
    w = cairo_image_surface_get_width(surface);
51
61
    h = cairo_image_surface_get_height(surface);
52
53
61
    char *buf = (char *) calloc(size + 1, sizeof(char));
54
61
    memcpy(buf, data, size);
55
61
    buf[size] = '\0';
56
57
61
    pattern = cairo_pattern_create_raster_source(buf, content, w, h);
58
61
    cairo_raster_source_pattern_set_acquire (pattern, acquire, release);
59
61
    cairo_set_source(cr, pattern);
60
61
    cairo_paint(cr);
61
62
61
    cairo_destroy(cr);
63
61
    cairo_pattern_destroy(pattern);
64
61
    cairo_surface_destroy(surface);
65
61
    free(buf);
66
61
    fuzzer_release_tmpfile(tmpfile);
67
61
    return 0;
68
6.13k
}