Coverage Report

Created: 2026-03-31 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fuzz/pixbuf_cons_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 <stdint.h>
16
#include <gdk-pixbuf/gdk-pixbuf.h>
17
18
290
#define WIDTH 10
19
200
#define HEIGHT 20
20
90
#define ROWSTRIDE (WIDTH * 4)
21
22
110
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
23
110
    if (!(size >= WIDTH * HEIGHT * 4)) {
24
20
        return 0;
25
20
    }
26
90
    const gchar *profile;
27
90
    GdkPixbuf *pixbuf, *tmp, *tmp2;
28
90
    GBytes *bytes;
29
90
    bytes = g_bytes_new_static(data, size);
30
90
    pixbuf = g_object_new(GDK_TYPE_PIXBUF,
31
90
            "width", WIDTH,
32
90
            "height", HEIGHT,
33
90
            "rowstride", ROWSTRIDE,
34
90
            "bits-per-sample", 8,"n-channels", 3,
35
90
            "has-alpha", FALSE,
36
90
            "pixel-bytes", bytes,
37
90
            NULL);
38
90
    if (pixbuf == NULL) {
39
0
        g_bytes_unref(bytes);
40
0
        return 0;
41
0
    }
42
43
90
    tmp = gdk_pixbuf_scale_simple(pixbuf,
44
90
            gdk_pixbuf_get_width(pixbuf) / 4,
45
90
            gdk_pixbuf_get_height(pixbuf) / 4,
46
90
            GDK_INTERP_NEAREST);
47
90
    if (tmp) g_object_unref(tmp);
48
49
90
    unsigned int rot_amount = ((unsigned int) data[0]) % 4;
50
90
    tmp = gdk_pixbuf_rotate_simple(pixbuf, rot_amount * 90);
51
90
    if (tmp) g_object_unref(tmp);
52
53
90
    tmp = gdk_pixbuf_flip(pixbuf, TRUE);
54
90
    if (tmp) g_object_unref(tmp);
55
56
90
    tmp = gdk_pixbuf_composite_color_simple(pixbuf,
57
90
            gdk_pixbuf_get_width(pixbuf) / 4,
58
90
            gdk_pixbuf_get_height(pixbuf) / 4,
59
90
            GDK_INTERP_NEAREST,
60
90
            128,
61
90
            8,
62
90
            G_MAXUINT32,
63
90
            G_MAXUINT32/2);
64
90
    if (tmp) g_object_unref(tmp);
65
66
90
    char *buf = (char *) calloc(size + 1, sizeof(char));
67
90
    memcpy(buf, data, size);
68
90
    buf[size] = '\0';
69
70
90
    gdk_pixbuf_set_option(pixbuf, buf, buf);
71
90
    profile = gdk_pixbuf_get_option(pixbuf, buf);
72
90
    tmp = gdk_pixbuf_new_from_data(gdk_pixbuf_get_pixels(pixbuf),
73
90
            GDK_COLORSPACE_RGB,
74
90
            FALSE,
75
90
            gdk_pixbuf_get_bits_per_sample(pixbuf),
76
90
            gdk_pixbuf_get_width(pixbuf),
77
90
            gdk_pixbuf_get_height(pixbuf),
78
90
            gdk_pixbuf_get_rowstride(pixbuf),
79
90
            NULL,
80
90
            NULL);
81
90
    tmp2 = gdk_pixbuf_flip(tmp, TRUE);
82
90
    if (tmp) g_object_unref(tmp);
83
84
90
    free(buf);
85
90
    g_bytes_unref(bytes);
86
90
    g_object_unref(pixbuf);
87
90
    if (tmp2) g_object_unref(tmp2);
88
90
    return 0;
89
90
}