Coverage Report

Created: 2026-10-17 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fuzz/text_glyphs_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
const int glyph_range = 9;
19
20
424
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
21
424
    if (size < glyph_range) {
22
5
        return 0;
23
5
    }
24
419
    cairo_t *cr;
25
419
    cairo_surface_t *surface;
26
419
    cairo_status_t status;
27
419
    cairo_text_extents_t extents;
28
419
    cairo_text_cluster_t cluster;
29
30
419
    char *tmpfile = fuzzer_get_tmpfile(data, size);
31
419
    surface = cairo_image_surface_create_from_png(tmpfile);
32
419
    status = cairo_surface_status(surface);
33
419
    if (status != CAIRO_STATUS_SUCCESS) {
34
335
        fuzzer_release_tmpfile(tmpfile);
35
335
        return 0;
36
335
    }
37
38
84
    char *buf = (char *) calloc(size + 1, sizeof(char));
39
84
    memcpy(buf, data, size);
40
84
    buf[size] = '\0';
41
42
84
    cr = cairo_create(surface);
43
84
    cairo_text_extents(cr, buf, &extents);
44
84
    cluster.num_bytes = size;
45
84
    cluster.num_glyphs = 1;
46
840
    for (int i = 0; i < glyph_range; i++) {
47
        // Taken from test/text-glyph-range.c
48
756
        cairo_glyph_t glyph = {
49
756
            (long int)data[i], 10 * i, 25
50
756
        };
51
756
        cairo_show_text_glyphs(cr, buf, size, &glyph, 1, &cluster, 1, 0);
52
756
    }
53
54
84
    cairo_destroy(cr);
55
84
    cairo_surface_destroy(surface);
56
84
    free(buf);
57
84
    fuzzer_release_tmpfile(tmpfile);
58
84
    return 0;
59
419
}