Coverage Report

Created: 2025-11-16 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fuzz/surface_write_png_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
5.35k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
19
5.35k
    cairo_surface_t *image;
20
5.35k
    cairo_surface_t *surface;
21
5.35k
    cairo_status_t status;
22
5.35k
    cairo_format_t format;
23
24
5.35k
    char *tmpfile = fuzzer_get_tmpfile(data, size);
25
5.35k
    image = cairo_image_surface_create_from_png(tmpfile);
26
5.35k
    status = cairo_surface_status (image);
27
5.35k
    if (status != CAIRO_STATUS_SUCCESS) {
28
5.24k
        fuzzer_release_tmpfile(tmpfile);
29
5.24k
        return 0;
30
5.24k
    }
31
32
113
    format = cairo_image_surface_get_format(image);
33
113
    surface = cairo_image_surface_create_for_data((unsigned char*)data, format, 1, 1, size);
34
113
    status = cairo_surface_status (surface);
35
113
    if (status != CAIRO_STATUS_SUCCESS) {
36
55
        cairo_surface_destroy(image);
37
55
        fuzzer_release_tmpfile(tmpfile);
38
55
        return 0;
39
55
    }
40
58
    cairo_surface_write_to_png(surface, tmpfile);
41
42
58
    cairo_surface_destroy(surface);
43
58
    cairo_surface_destroy(image);
44
58
    fuzzer_release_tmpfile(tmpfile);
45
58
    return 0;
46
113
}