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