Coverage Report

Created: 2025-07-23 06:50

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