blob: 09b9a9a4f2da087598d3fa2e2b5b5eb5e9ecd13a [file] [log] [blame]
mtklein65e58242016-01-13 12:57:57 -08001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "fuzz/Fuzz.h"
9#include "include/codec/SkCodec.h"
10#include "include/core/SkCanvas.h"
11#include "include/core/SkData.h"
12#include "include/core/SkImage.h"
13#include "include/core/SkImageEncoder.h"
14#include "include/core/SkMallocPixelRef.h"
15#include "include/core/SkPaint.h"
16#include "include/core/SkPath.h"
17#include "include/core/SkStream.h"
18#include "include/core/SkSurface.h"
19#include "include/core/SkTextBlob.h"
Kevin Lubickd7255a72019-06-03 11:59:23 -040020#include "src/core/SkFontMgrPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050021#include "src/core/SkOSFile.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "src/core/SkReadBuffer.h"
23#include "src/utils/SkOSPath.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "tools/ToolUtils.h"
Kevin Lubickd7255a72019-06-03 11:59:23 -040025#include "tools/flags/CommandLineFlags.h"
26#include "tools/fonts/TestFontMgr.h"
Hal Canary8a001442018-09-19 11:31:27 -040027
Hal Canary62176db2017-02-27 16:42:03 -050028#include <iostream>
Kevin Lubickacd456a2018-04-24 13:58:16 -040029#include <map>
Kevin Lubickfffa6412018-04-23 16:44:55 -040030#include <regex>
mtkleina1159422016-01-15 05:46:54 -080031#include <signal.h>
Kevin Lubick2541edf2018-01-11 10:27:14 -050032
Mike Klein84836b72019-03-21 11:31:36 -050033static DEFINE_string2(bytes, b, "", "A path to a file or a directory. If a file, the "
34 "contents will be used as the fuzz bytes. If a directory, all files "
35 "in the directory will be used as fuzz bytes for the fuzzer, one at a "
36 "time.");
37static DEFINE_string2(name, n, "", "If --type is 'api', fuzz the API with this name.");
38static DEFINE_string2(dump, d, "", "If not empty, dump 'image*' or 'skp' types as a "
39 "PNG with this name.");
Brian Osmanf4e57372020-07-17 11:37:14 -040040static DEFINE_int(loops, 1, "Run the fuzzer on each input this many times.");
Kevin Lubick9ff5dc92018-01-09 12:47:33 -050041DEFINE_bool2(verbose, v, false, "Print more information while fuzzing.");
Florin Malita7796f002018-06-08 12:25:38 -040042
43// This cannot be inlined in DEFINE_string2 due to interleaved ifdefs
44static constexpr char g_type_message[] = "How to interpret --bytes, one of:\n"
Kevin Lubick0f3d2a62018-10-17 10:24:44 -040045 "android_codec\n"
Florin Malita7796f002018-06-08 12:25:38 -040046 "animated_image_decode\n"
47 "api\n"
48 "color_deserialize\n"
49 "filter_fuzz (equivalent to Chrome's filter_fuzz_stub)\n"
50 "image_decode\n"
Kevin Lubick0f3d2a62018-10-17 10:24:44 -040051 "image_decode_incremental\n"
Florin Malita7796f002018-06-08 12:25:38 -040052 "image_mode\n"
53 "image_scale\n"
Florin Malita80452be2018-06-19 11:27:20 -040054 "json\n"
Florin Malita7796f002018-06-08 12:25:38 -040055 "path_deserialize\n"
Florin Malita7796f002018-06-08 12:25:38 -040056 "region_deserialize\n"
57 "region_set_path\n"
Kevin Lubick2be14d32019-10-21 13:44:48 -040058 "skdescriptor_deserialize\n"
Florin Malita7796f002018-06-08 12:25:38 -040059 "skp\n"
Zepeng Hua5783f32020-07-10 13:36:20 +000060 "skruntimeeffect\n"
Florin Malita7796f002018-06-08 12:25:38 -040061 "sksl2glsl\n"
Zepeng Huedaf3022020-06-12 12:20:59 +000062 "svg_dom\n"
Kevin Lubicke9c1ce82019-03-11 11:09:40 -040063 "sksl2metal\n"
Kevin Lubick0f0a7102019-03-18 16:20:55 -040064 "sksl2pipeline\n"
Kevin Lubicke9c1ce82019-03-11 11:09:40 -040065 "sksl2spirv\n"
Florin Malita7796f002018-06-08 12:25:38 -040066#if defined(SK_ENABLE_SKOTTIE)
67 "skottie_json\n"
68#endif
69 "textblob";
70
Mike Klein84836b72019-03-21 11:31:36 -050071static DEFINE_string2(type, t, "", g_type_message);
kjlubickdba57342016-01-21 05:03:28 -080072
Kevin Lubickfffa6412018-04-23 16:44:55 -040073static int fuzz_file(SkString path, SkString type);
kjlubick2a42f482016-02-16 16:14:23 -080074static uint8_t calculate_option(SkData*);
Kevin Lubickfffa6412018-04-23 16:44:55 -040075static SkString try_auto_detect(SkString path, SkString* name);
kjlubickdba57342016-01-21 05:03:28 -080076
Kevin Lubick0f3d2a62018-10-17 10:24:44 -040077static void fuzz_android_codec(sk_sp<SkData>);
78static void fuzz_animated_img(sk_sp<SkData>);
Kevin Lubickfffa6412018-04-23 16:44:55 -040079static void fuzz_api(sk_sp<SkData> bytes, SkString name);
Kevin Lubickf80f1152017-01-06 08:26:56 -050080static void fuzz_color_deserialize(sk_sp<SkData>);
Kevin Lubickd46e85f2017-11-21 17:13:35 -050081static void fuzz_filter_fuzz(sk_sp<SkData>);
Kevin Lubick0f3d2a62018-10-17 10:24:44 -040082static void fuzz_image_decode(sk_sp<SkData>);
83static void fuzz_image_decode_incremental(sk_sp<SkData>);
Kevin Lubick0168e042017-02-14 13:12:37 -050084static void fuzz_img(sk_sp<SkData>, uint8_t, uint8_t);
Florin Malita80452be2018-06-19 11:27:20 -040085static void fuzz_json(sk_sp<SkData>);
Kevin Lubickf04c50a2017-01-06 13:48:19 -050086static void fuzz_path_deserialize(sk_sp<SkData>);
Kevin Lubickedee1ae2017-02-20 17:47:18 -050087static void fuzz_region_deserialize(sk_sp<SkData>);
Kevin Lubick2541edf2018-01-11 10:27:14 -050088static void fuzz_region_set_path(sk_sp<SkData>);
Kevin Lubick2be14d32019-10-21 13:44:48 -040089static void fuzz_skdescriptor_deserialize(sk_sp<SkData>);
Kevin Lubick0168e042017-02-14 13:12:37 -050090static void fuzz_skp(sk_sp<SkData>);
Zepeng Hua5783f32020-07-10 13:36:20 +000091static void fuzz_skruntimeeffect(sk_sp<SkData>);
Kevin Lubicke9c1ce82019-03-11 11:09:40 -040092static void fuzz_sksl2glsl(sk_sp<SkData>);
93static void fuzz_sksl2metal(sk_sp<SkData>);
Kevin Lubick0f0a7102019-03-18 16:20:55 -040094static void fuzz_sksl2pipeline(sk_sp<SkData>);
Kevin Lubick2be14d32019-10-21 13:44:48 -040095static void fuzz_sksl2spirv(sk_sp<SkData>);
Kevin Lubickd46e85f2017-11-21 17:13:35 -050096static void fuzz_textblob_deserialize(sk_sp<SkData>);
Herb Derbya839fc02017-03-16 12:30:43 -040097
Kevin Lubickfffa6412018-04-23 16:44:55 -040098static void print_api_names();
99
Robert Phillips2af13c12021-09-01 16:47:01 +0000100#if defined(SK_ENABLE_SVG)
101static void fuzz_svg_dom(sk_sp<SkData>);
102#endif
103
Florin Malita0b0d93d2018-05-04 15:01:03 -0400104#if defined(SK_ENABLE_SKOTTIE)
105static void fuzz_skottie_json(sk_sp<SkData>);
106#endif
107
mtklein65e58242016-01-13 12:57:57 -0800108int main(int argc, char** argv) {
Mike Klein88544fb2019-03-20 10:50:33 -0500109 CommandLineFlags::SetUsage(
110 "Usage: fuzz -t <type> -b <path/to/file> [-n api-to-fuzz]\n"
111 " fuzz -b <path/to/file>\n"
112 "--help lists the valid types. If type is not specified,\n"
113 "fuzz will make a guess based on the name of the file.\n");
114 CommandLineFlags::Parse(argc, argv);
Kevin Lubickd7255a72019-06-03 11:59:23 -0400115 gSkFontMgr_DefaultFactory = &ToolUtils::MakePortableFontMgr;
mtkleinf5e97822016-01-15 06:19:53 -0800116
Kevin Lubickfffa6412018-04-23 16:44:55 -0400117 SkString path = SkString(FLAGS_bytes.isEmpty() ? argv[0] : FLAGS_bytes[0]);
118 SkString type = SkString(FLAGS_type.isEmpty() ? "" : FLAGS_type[0]);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500119
Brian Osmanf4e57372020-07-17 11:37:14 -0400120 int loopCount = std::max(FLAGS_loops, 1);
121
Kevin Lubickfffa6412018-04-23 16:44:55 -0400122 if (!sk_isdir(path.c_str())) {
Brian Osmanf4e57372020-07-17 11:37:14 -0400123 for (int i = 0; i < loopCount; ++i) {
124 int rv = fuzz_file(path, type);
125 if (rv != 0) {
126 return rv;
127 }
128 }
129 return 0;
Kevin Lubickf80f1152017-01-06 08:26:56 -0500130 }
131
Kevin Lubickfffa6412018-04-23 16:44:55 -0400132 SkOSFile::Iter it(path.c_str());
Kevin Lubickf80f1152017-01-06 08:26:56 -0500133 for (SkString file; it.next(&file); ) {
Kevin Lubickfffa6412018-04-23 16:44:55 -0400134 SkString p = SkOSPath::Join(path.c_str(), file.c_str());
Kevin Lubickf80f1152017-01-06 08:26:56 -0500135 SkDebugf("Fuzzing %s\n", p.c_str());
Brian Osmanf4e57372020-07-17 11:37:14 -0400136 for (int i = 0; i < loopCount; ++i) {
137 int rv = fuzz_file(p, type);
138 if (rv != 0) {
139 return rv;
140 }
Kevin Lubickf80f1152017-01-06 08:26:56 -0500141 }
142 }
143 return 0;
144}
145
Kevin Lubickfffa6412018-04-23 16:44:55 -0400146static int fuzz_file(SkString path, SkString type) {
147 sk_sp<SkData> bytes(SkData::MakeFromFileName(path.c_str()));
kjlubickdba57342016-01-21 05:03:28 -0800148 if (!bytes) {
Kevin Lubickfffa6412018-04-23 16:44:55 -0400149 SkDebugf("Could not read %s\n", path.c_str());
Kevin Lubickf80f1152017-01-06 08:26:56 -0500150 return 1;
kjlubickdba57342016-01-21 05:03:28 -0800151 }
mtklein65e58242016-01-13 12:57:57 -0800152
Kevin Lubickfffa6412018-04-23 16:44:55 -0400153 SkString name = SkString(FLAGS_name.isEmpty() ? "" : FLAGS_name[0]);
154
155 if (type.isEmpty()) {
156 type = try_auto_detect(path, &name);
kjlubickdba57342016-01-21 05:03:28 -0800157 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400158
159 if (type.isEmpty()) {
160 SkDebugf("Could not autodetect type of %s\n", path.c_str());
161 return 1;
162 }
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400163 if (type.equals("android_codec")) {
164 fuzz_android_codec(bytes);
165 return 0;
166 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400167 if (type.equals("animated_image_decode")) {
168 fuzz_animated_img(bytes);
169 return 0;
170 }
171 if (type.equals("api")) {
172 fuzz_api(bytes, name);
173 return 0;
174 }
175 if (type.equals("color_deserialize")) {
176 fuzz_color_deserialize(bytes);
177 return 0;
178 }
Florin Malita80452be2018-06-19 11:27:20 -0400179 if (type.equals("filter_fuzz")) {
180 fuzz_filter_fuzz(bytes);
181 return 0;
182 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400183 if (type.equals("image_decode")) {
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400184 fuzz_image_decode(bytes);
185 return 0;
186 }
187 if (type.equals("image_decode_incremental")) {
188 fuzz_image_decode_incremental(bytes);
Kevin Lubickfffa6412018-04-23 16:44:55 -0400189 return 0;
190 }
191 if (type.equals("image_scale")) {
192 uint8_t option = calculate_option(bytes.get());
193 fuzz_img(bytes, option, 0);
194 return 0;
195 }
196 if (type.equals("image_mode")) {
197 uint8_t option = calculate_option(bytes.get());
198 fuzz_img(bytes, 0, option);
199 return 0;
200 }
Florin Malita80452be2018-06-19 11:27:20 -0400201 if (type.equals("json")) {
202 fuzz_json(bytes);
Kevin Lubick9eeede22018-05-03 16:26:10 -0400203 return 0;
204 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400205 if (type.equals("path_deserialize")) {
206 fuzz_path_deserialize(bytes);
207 return 0;
208 }
209 if (type.equals("region_deserialize")) {
210 fuzz_region_deserialize(bytes);
211 return 0;
212 }
213 if (type.equals("region_set_path")) {
214 fuzz_region_set_path(bytes);
215 return 0;
216 }
217 if (type.equals("pipe")) {
Mike Klein60900b52018-09-21 11:19:45 -0400218 SkDebugf("I would prefer not to.\n");
Kevin Lubickfffa6412018-04-23 16:44:55 -0400219 return 0;
220 }
Kevin Lubick2be14d32019-10-21 13:44:48 -0400221 if (type.equals("skdescriptor_deserialize")) {
222 fuzz_skdescriptor_deserialize(bytes);
223 return 0;
224 }
Florin Malita0b0d93d2018-05-04 15:01:03 -0400225#if defined(SK_ENABLE_SKOTTIE)
Kevin Lubick9eeede22018-05-03 16:26:10 -0400226 if (type.equals("skottie_json")) {
227 fuzz_skottie_json(bytes);
Kevin Lubickfffa6412018-04-23 16:44:55 -0400228 return 0;
229 }
Florin Malita0b0d93d2018-05-04 15:01:03 -0400230#endif
Kevin Lubick9eeede22018-05-03 16:26:10 -0400231 if (type.equals("skp")) {
232 fuzz_skp(bytes);
Kevin Lubickfffa6412018-04-23 16:44:55 -0400233 return 0;
234 }
Zepeng Hua5783f32020-07-10 13:36:20 +0000235 if (type.equals("skruntimeeffect")) {
236 fuzz_skruntimeeffect(bytes);
237 return 0;
238 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400239 if (type.equals("sksl2glsl")) {
240 fuzz_sksl2glsl(bytes);
241 return 0;
242 }
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400243 if (type.equals("sksl2metal")) {
244 fuzz_sksl2metal(bytes);
245 return 0;
246 }
247 if (type.equals("sksl2spirv")) {
248 fuzz_sksl2spirv(bytes);
249 return 0;
250 }
Kevin Lubick0f0a7102019-03-18 16:20:55 -0400251 if (type.equals("sksl2pipeline")) {
252 fuzz_sksl2pipeline(bytes);
253 return 0;
254 }
Robert Phillips2af13c12021-09-01 16:47:01 +0000255#if defined(SK_ENABLE_SVG)
Zepeng Huedaf3022020-06-12 12:20:59 +0000256 if (type.equals("svg_dom")) {
257 fuzz_svg_dom(bytes);
258 return 0;
259 }
Robert Phillips2af13c12021-09-01 16:47:01 +0000260#endif
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400261 if (type.equals("textblob")) {
262 fuzz_textblob_deserialize(bytes);
263 return 0;
264 }
Kevin Lubick457fa972018-05-29 09:22:06 -0400265 SkDebugf("Unknown type %s\n", type.c_str());
Mike Klein88544fb2019-03-20 10:50:33 -0500266 CommandLineFlags::PrintUsage();
Kevin Lubick9ff5dc92018-01-09 12:47:33 -0500267 return 1;
kjlubickdba57342016-01-21 05:03:28 -0800268}
269
Kevin Lubickfffa6412018-04-23 16:44:55 -0400270static std::map<std::string, std::string> cf_api_map = {
Zepeng Hu94007012020-07-22 14:37:46 +0000271 {"api_create_ddl", "CreateDDL"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400272 {"api_draw_functions", "DrawFunctions"},
Adlai Hollerccb68662021-02-25 10:28:44 -0500273 {"api_ddl_threading", "DDLThreadingGL"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400274 {"api_gradients", "Gradients"},
275 {"api_image_filter", "ImageFilter"},
276 {"api_mock_gpu_canvas", "MockGPUCanvas"},
277 {"api_null_canvas", "NullCanvas"},
278 {"api_path_measure", "PathMeasure"},
Kevin Lubickde54d7c2018-09-24 08:48:19 -0400279 {"api_pathop", "Pathop"},
Kevin Lubick57507f12018-10-11 09:35:15 -0400280 {"api_polyutils", "PolyUtils"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400281 {"api_raster_n32_canvas", "RasterN32Canvas"},
Weston Tracey1a771fe2021-02-04 11:09:59 -0500282 {"api_skparagraph", "SkParagraph"},
Zepeng Huba7cbf72020-07-01 13:21:03 +0000283 {"api_svg_canvas", "SVGCanvas"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400284 {"jpeg_encoder", "JPEGEncoder"},
285 {"png_encoder", "PNGEncoder"},
Kevin Lubickf84ded22018-10-23 09:28:48 -0400286 {"skia_pathop_fuzzer", "LegacyChromiumPathop"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400287 {"webp_encoder", "WEBPEncoder"}
288};
289
Kevin Lubick6c560552018-06-20 09:29:23 -0400290// maps clusterfuzz/oss-fuzz -> Skia's name
Kevin Lubickfffa6412018-04-23 16:44:55 -0400291static std::map<std::string, std::string> cf_map = {
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400292 {"android_codec", "android_codec"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400293 {"animated_image_decode", "animated_image_decode"},
294 {"image_decode", "image_decode"},
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400295 {"image_decode_incremental", "image_decode_incremental"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400296 {"image_filter_deserialize", "filter_fuzz"},
297 {"image_filter_deserialize_width", "filter_fuzz"},
298 {"path_deserialize", "path_deserialize"},
299 {"region_deserialize", "region_deserialize"},
300 {"region_set_path", "region_set_path"},
Kevin Lubick2be14d32019-10-21 13:44:48 -0400301 {"skdescriptor_deserialize", "skdescriptor_deserialize"},
Kevin Lubick6c560552018-06-20 09:29:23 -0400302 {"skjson", "json"},
Zepeng Hufcb7ba02020-07-31 17:21:29 +0000303 {"skp", "skp"},
Zepeng Hua5783f32020-07-10 13:36:20 +0000304 {"skruntimeeffect", "skruntimeeffect"},
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400305 {"sksl2glsl", "sksl2glsl"},
306 {"sksl2metal", "sksl2metal"},
307 {"sksl2spirv", "sksl2spirv"},
Kevin Lubick0f0a7102019-03-18 16:20:55 -0400308 {"sksl2pipeline", "sksl2pipeline"},
Kevin Lubickde54d7c2018-09-24 08:48:19 -0400309#if defined(SK_ENABLE_SKOTTIE)
310 {"skottie_json", "skottie_json"},
311#endif
Robert Phillips2af13c12021-09-01 16:47:01 +0000312#if defined(SK_ENABLE_SVG)
Zepeng Huedaf3022020-06-12 12:20:59 +0000313 {"svg_dom", "svg_dom"},
Robert Phillips2af13c12021-09-01 16:47:01 +0000314#endif
Kevin Lubickfffa6412018-04-23 16:44:55 -0400315 {"textblob_deserialize", "textblob"}
316};
317
318static SkString try_auto_detect(SkString path, SkString* name) {
319 std::cmatch m;
320 std::regex clusterfuzz("clusterfuzz-testcase(-minimized)?-([a-z0-9_]+)-[\\d]+");
321 std::regex skiafuzzer("(api-)?(\\w+)-[a-f0-9]+");
322
323 if (std::regex_search(path.c_str(), m, clusterfuzz)) {
324 std::string type = m.str(2);
Kevin Lubick6c560552018-06-20 09:29:23 -0400325
326 if (cf_api_map.find(type) != cf_api_map.end()) {
327 *name = SkString(cf_api_map[type].c_str());
328 return SkString("api");
Kevin Lubickfffa6412018-04-23 16:44:55 -0400329 } else {
330 if (cf_map.find(type) != cf_map.end()) {
331 return SkString(cf_map[type].c_str());
332 }
333 }
334 } else if (std::regex_search(path.c_str(), m, skiafuzzer)) {
335 std::string a1 = m.str(1);
336 std::string typeOrName = m.str(2);
337 if (a1.length() > 0) {
338 // it's an api fuzzer
339 *name = SkString(typeOrName.c_str());
340 return SkString("api");
341 } else {
342 return SkString(typeOrName.c_str());
343 }
344 }
345
346 return SkString("");
347}
348
Florin Malita80452be2018-06-19 11:27:20 -0400349void FuzzJSON(sk_sp<SkData> bytes);
Florin Malita7796f002018-06-08 12:25:38 -0400350
Florin Malita80452be2018-06-19 11:27:20 -0400351static void fuzz_json(sk_sp<SkData> bytes){
352 FuzzJSON(bytes);
Florin Malita7796f002018-06-08 12:25:38 -0400353 SkDebugf("[terminated] Done parsing!\n");
354}
Florin Malita7796f002018-06-08 12:25:38 -0400355
Florin Malita0b0d93d2018-05-04 15:01:03 -0400356#if defined(SK_ENABLE_SKOTTIE)
Kevin Lubick9eeede22018-05-03 16:26:10 -0400357void FuzzSkottieJSON(sk_sp<SkData> bytes);
358
359static void fuzz_skottie_json(sk_sp<SkData> bytes){
360 FuzzSkottieJSON(bytes);
361 SkDebugf("[terminated] Done animating!\n");
362}
Florin Malita0b0d93d2018-05-04 15:01:03 -0400363#endif
Kevin Lubick9eeede22018-05-03 16:26:10 -0400364
Robert Phillips2af13c12021-09-01 16:47:01 +0000365#if defined(SK_ENABLE_SVG)
Zepeng Huedaf3022020-06-12 12:20:59 +0000366void FuzzSVG(sk_sp<SkData> bytes);
Robert Phillips2af13c12021-09-01 16:47:01 +0000367
Zepeng Huedaf3022020-06-12 12:20:59 +0000368static void fuzz_svg_dom(sk_sp<SkData> bytes){
369 FuzzSVG(bytes);
370 SkDebugf("[terminated] Done DOM!\n");
371}
Robert Phillips2af13c12021-09-01 16:47:01 +0000372#endif
Zepeng Huedaf3022020-06-12 12:20:59 +0000373
kjlubick2a42f482016-02-16 16:14:23 -0800374// This adds up the first 1024 bytes and returns it as an 8 bit integer. This allows afl-fuzz to
375// deterministically excercise different paths, or *options* (such as different scaling sizes or
376// different image modes) without needing to introduce a parameter. This way we don't need a
377// image_scale1, image_scale2, image_scale4, etc fuzzer, we can just have a image_scale fuzzer.
378// Clients are expected to transform this number into a different range, e.g. with modulo (%).
379static uint8_t calculate_option(SkData* bytes) {
380 uint8_t total = 0;
381 const uint8_t* data = bytes->bytes();
382 for (size_t i = 0; i < 1024 && i < bytes->size(); i++) {
383 total += data[i];
384 }
385 return total;
386}
387
Kevin Lubickfffa6412018-04-23 16:44:55 -0400388static void print_api_names(){
389 SkDebugf("When using --type api, please choose an API to fuzz with --name/-n:\n");
Hal Canary972eba32018-07-30 17:07:07 -0400390 for (const Fuzzable& fuzzable : sk_tools::Registry<Fuzzable>::Range()) {
Kevin Lubickfffa6412018-04-23 16:44:55 -0400391 SkDebugf("\t%s\n", fuzzable.name);
392 }
393}
394
395static void fuzz_api(sk_sp<SkData> bytes, SkString name) {
Hal Canary972eba32018-07-30 17:07:07 -0400396 for (const Fuzzable& fuzzable : sk_tools::Registry<Fuzzable>::Range()) {
Kevin Lubickfffa6412018-04-23 16:44:55 -0400397 if (name.equals(fuzzable.name)) {
mtkleinf5e97822016-01-15 06:19:53 -0800398 SkDebugf("Fuzzing %s...\n", fuzzable.name);
Kevin Lubick1ac8fd22017-03-01 10:42:45 -0500399 Fuzz fuzz(std::move(bytes));
mtklein65e58242016-01-13 12:57:57 -0800400 fuzzable.fn(&fuzz);
kjlubick47d158e2016-02-01 08:23:50 -0800401 SkDebugf("[terminated] Success!\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500402 return;
mtklein65e58242016-01-13 12:57:57 -0800403 }
404 }
mtkleind4387ea2016-01-21 06:13:52 -0800405
Kevin Lubickfffa6412018-04-23 16:44:55 -0400406 print_api_names();
kjlubickdba57342016-01-21 05:03:28 -0800407}
408
409static void dump_png(SkBitmap bitmap) {
410 if (!FLAGS_dump.isEmpty()) {
Mike Kleinea3f0142019-03-20 11:12:10 -0500411 ToolUtils::EncodeImageToFile(FLAGS_dump[0], bitmap, SkEncodedImageFormat::kPNG, 100);
kjlubickdba57342016-01-21 05:03:28 -0800412 SkDebugf("Dumped to %s\n", FLAGS_dump[0]);
413 }
414}
415
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400416bool FuzzAnimatedImage(sk_sp<SkData> bytes);
Kevin Lubick2416f962018-02-12 08:26:39 -0500417
418static void fuzz_animated_img(sk_sp<SkData> bytes) {
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400419 if (FuzzAnimatedImage(bytes)) {
420 SkDebugf("[terminated] Success from decoding/drawing animated image!\n");
421 return;
422 }
423 SkDebugf("[terminated] Could not decode or draw animated image.\n");
Kevin Lubick2416f962018-02-12 08:26:39 -0500424}
425
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400426bool FuzzImageDecode(sk_sp<SkData> bytes);
Kevin Lubick2416f962018-02-12 08:26:39 -0500427
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400428static void fuzz_image_decode(sk_sp<SkData> bytes) {
429 if (FuzzImageDecode(bytes)) {
430 SkDebugf("[terminated] Success from decoding/drawing image!\n");
431 return;
432 }
433 SkDebugf("[terminated] Could not decode or draw image.\n");
Kevin Lubick2416f962018-02-12 08:26:39 -0500434}
435
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400436bool FuzzIncrementalImageDecode(sk_sp<SkData> bytes);
437
438static void fuzz_image_decode_incremental(sk_sp<SkData> bytes) {
439 if (FuzzIncrementalImageDecode(bytes)) {
440 SkDebugf("[terminated] Success using incremental decode!\n");
441 return;
442 }
443 SkDebugf("[terminated] Could not incrementally decode and image.\n");
444}
445
446bool FuzzAndroidCodec(sk_sp<SkData> bytes, uint8_t sampleSize);
447
448static void fuzz_android_codec(sk_sp<SkData> bytes) {
449 Fuzz fuzz(bytes);
450 uint8_t sampleSize;
451 fuzz.nextRange(&sampleSize, 1, 64);
452 bytes = SkData::MakeSubset(bytes.get(), 1, bytes->size() - 1);
453 if (FuzzAndroidCodec(bytes, sampleSize)) {
454 SkDebugf("[terminated] Success on Android Codec sampleSize=%u!\n", sampleSize);
455 return;
456 }
457 SkDebugf("[terminated] Could not use Android Codec sampleSize=%u!\n", sampleSize);
458}
459
460// This is a "legacy" fuzzer that likely does too much. It was based off of how
461// DM reads in images. image_decode, image_decode_incremental and android_codec
462// are more targeted fuzzers that do a subset of what this one does.
Kevin Lubickf80f1152017-01-06 08:26:56 -0500463static void fuzz_img(sk_sp<SkData> bytes, uint8_t scale, uint8_t mode) {
kjlubick2a42f482016-02-16 16:14:23 -0800464 // We can scale 1x, 2x, 4x, 8x, 16x
465 scale = scale % 5;
kjlubick5bd98a22016-02-18 06:27:38 -0800466 float fscale = (float)pow(2.0f, scale);
467 SkDebugf("Scaling factor: %f\n", fscale);
kjlubick2a42f482016-02-16 16:14:23 -0800468
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500469 // We have 5 different modes of decoding.
470 mode = mode % 5;
kjlubick2a42f482016-02-16 16:14:23 -0800471 SkDebugf("Mode: %d\n", mode);
472
473 // This is mostly copied from DMSrcSink's CodecSrc::draw method.
kjlubick47d158e2016-02-01 08:23:50 -0800474 SkDebugf("Decoding\n");
Mike Reedede7bac2017-07-23 15:30:02 -0400475 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(bytes));
John Stilesa008b0f2020-08-16 08:48:02 -0400476 if (nullptr == codec) {
kjlubick47d158e2016-02-01 08:23:50 -0800477 SkDebugf("[terminated] Couldn't create codec.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500478 return;
kjlubickdba57342016-01-21 05:03:28 -0800479 }
480
481 SkImageInfo decodeInfo = codec->getInfo();
kjlubick2a42f482016-02-16 16:14:23 -0800482 SkISize size = codec->getScaledDimensions(fscale);
Brian Salomon9241a6d2019-10-03 13:26:54 -0400483 decodeInfo = decodeInfo.makeDimensions(size);
kjlubick2a42f482016-02-16 16:14:23 -0800484
kjlubickdba57342016-01-21 05:03:28 -0800485 SkBitmap bitmap;
kjlubickdba57342016-01-21 05:03:28 -0800486 SkCodec::Options options;
487 options.fZeroInitialized = SkCodec::kYes_ZeroInitialized;
488
Mike Reed086a4272017-07-18 10:53:11 -0400489 if (!bitmap.tryAllocPixelsFlags(decodeInfo, SkBitmap::kZeroPixels_AllocFlag)) {
kjlubick47d158e2016-02-01 08:23:50 -0800490 SkDebugf("[terminated] Could not allocate memory. Image might be too large (%d x %d)",
kjlubick2a42f482016-02-16 16:14:23 -0800491 decodeInfo.width(), decodeInfo.height());
Kevin Lubickf80f1152017-01-06 08:26:56 -0500492 return;
kjlubickdba57342016-01-21 05:03:28 -0800493 }
494
kjlubick2a42f482016-02-16 16:14:23 -0800495 switch (mode) {
496 case 0: {//kCodecZeroInit_Mode, kCodec_Mode
Leon Scroggins571b30f2017-07-11 17:35:31 +0000497 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes(), &options)) {
kjlubick2a42f482016-02-16 16:14:23 -0800498 case SkCodec::kSuccess:
499 SkDebugf("[terminated] Success!\n");
500 break;
501 case SkCodec::kIncompleteInput:
502 SkDebugf("[terminated] Partial Success\n");
503 break;
Leon Scroggins III674a1842017-07-06 12:26:09 -0400504 case SkCodec::kErrorInInput:
505 SkDebugf("[terminated] Partial Success with error\n");
506 break;
kjlubick2a42f482016-02-16 16:14:23 -0800507 case SkCodec::kInvalidConversion:
508 SkDebugf("Incompatible colortype conversion\n");
509 // Crash to allow afl-fuzz to know this was a bug.
510 raise(SIGSEGV);
John Stiles30212b72020-06-11 17:55:07 -0400511 break;
kjlubick2a42f482016-02-16 16:14:23 -0800512 default:
513 SkDebugf("[terminated] Couldn't getPixels.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500514 return;
kjlubick2a42f482016-02-16 16:14:23 -0800515 }
516 break;
517 }
518 case 1: {//kScanline_Mode
Leon Scroggins571b30f2017-07-11 17:35:31 +0000519 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo)) {
520 SkDebugf("[terminated] Could not start scanline decoder\n");
521 return;
522 }
kjlubick2a42f482016-02-16 16:14:23 -0800523
524 void* dst = bitmap.getAddr(0, 0);
525 size_t rowBytes = bitmap.rowBytes();
526 uint32_t height = decodeInfo.height();
Brian Osmanea176c62018-04-06 15:28:23 -0400527 // We do not need to check the return value. On an incomplete
528 // image, memory will be filled with a default value.
529 codec->getScanlines(dst, height, rowBytes);
kjlubick47d158e2016-02-01 08:23:50 -0800530 SkDebugf("[terminated] Success!\n");
kjlubickdba57342016-01-21 05:03:28 -0800531 break;
kjlubick2a42f482016-02-16 16:14:23 -0800532 }
533 case 2: { //kStripe_Mode
534 const int height = decodeInfo.height();
535 // This value is chosen arbitrarily. We exercise more cases by choosing a value that
536 // does not align with image blocks.
537 const int stripeHeight = 37;
538 const int numStripes = (height + stripeHeight - 1) / stripeHeight;
539
540 // Decode odd stripes
Leon Scroggins571b30f2017-07-11 17:35:31 +0000541 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo)
kjlubick2a42f482016-02-16 16:14:23 -0800542 || SkCodec::kTopDown_SkScanlineOrder != codec->getScanlineOrder()) {
543 // This mode was designed to test the new skip scanlines API in libjpeg-turbo.
544 // Jpegs have kTopDown_SkScanlineOrder, and at this time, it is not interesting
545 // to run this test for image types that do not have this scanline ordering.
546 SkDebugf("[terminated] Could not start top-down scanline decoder\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500547 return;
kjlubick2a42f482016-02-16 16:14:23 -0800548 }
549
550 for (int i = 0; i < numStripes; i += 2) {
551 // Skip a stripe
Brian Osman788b9162020-02-07 10:36:46 -0500552 const int linesToSkip = std::min(stripeHeight, height - i * stripeHeight);
kjlubick2a42f482016-02-16 16:14:23 -0800553 codec->skipScanlines(linesToSkip);
554
555 // Read a stripe
556 const int startY = (i + 1) * stripeHeight;
Brian Osman788b9162020-02-07 10:36:46 -0500557 const int linesToRead = std::min(stripeHeight, height - startY);
kjlubick2a42f482016-02-16 16:14:23 -0800558 if (linesToRead > 0) {
559 codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitmap.rowBytes());
560 }
561 }
562
563 // Decode even stripes
Leon Scroggins571b30f2017-07-11 17:35:31 +0000564 const SkCodec::Result startResult = codec->startScanlineDecode(decodeInfo);
kjlubick2a42f482016-02-16 16:14:23 -0800565 if (SkCodec::kSuccess != startResult) {
566 SkDebugf("[terminated] Failed to restart scanline decoder with same parameters.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500567 return;
kjlubick2a42f482016-02-16 16:14:23 -0800568 }
569 for (int i = 0; i < numStripes; i += 2) {
570 // Read a stripe
571 const int startY = i * stripeHeight;
Brian Osman788b9162020-02-07 10:36:46 -0500572 const int linesToRead = std::min(stripeHeight, height - startY);
kjlubick2a42f482016-02-16 16:14:23 -0800573 codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitmap.rowBytes());
574
575 // Skip a stripe
Brian Osman788b9162020-02-07 10:36:46 -0500576 const int linesToSkip = std::min(stripeHeight, height - (i + 1) * stripeHeight);
kjlubick2a42f482016-02-16 16:14:23 -0800577 if (linesToSkip > 0) {
578 codec->skipScanlines(linesToSkip);
579 }
580 }
581 SkDebugf("[terminated] Success!\n");
kjlubickdba57342016-01-21 05:03:28 -0800582 break;
kjlubick2a42f482016-02-16 16:14:23 -0800583 }
584 case 3: { //kSubset_Mode
585 // Arbitrarily choose a divisor.
586 int divisor = 2;
587 // Total width/height of the image.
588 const int W = codec->getInfo().width();
589 const int H = codec->getInfo().height();
590 if (divisor > W || divisor > H) {
591 SkDebugf("[terminated] Cannot codec subset: divisor %d is too big "
592 "with dimensions (%d x %d)\n", divisor, W, H);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500593 return;
kjlubick2a42f482016-02-16 16:14:23 -0800594 }
595 // subset dimensions
596 // SkWebpCodec, the only one that supports subsets, requires even top/left boundaries.
597 const int w = SkAlign2(W / divisor);
598 const int h = SkAlign2(H / divisor);
599 SkIRect subset;
600 SkCodec::Options opts;
601 opts.fSubset = &subset;
602 SkBitmap subsetBm;
603 // We will reuse pixel memory from bitmap.
604 void* pixels = bitmap.getPixels();
kjlubick2a42f482016-02-16 16:14:23 -0800605 for (int x = 0; x < W; x += w) {
kjlubick2a42f482016-02-16 16:14:23 -0800606 for (int y = 0; y < H; y+= h) {
607 // Do not make the subset go off the edge of the image.
Brian Osman788b9162020-02-07 10:36:46 -0500608 const int preScaleW = std::min(w, W - x);
609 const int preScaleH = std::min(h, H - y);
kjlubick2a42f482016-02-16 16:14:23 -0800610 subset.setXYWH(x, y, preScaleW, preScaleH);
611 // And fscale
612 // FIXME: Should we have a version of getScaledDimensions that takes a subset
613 // into account?
614 decodeInfo = decodeInfo.makeWH(
Brian Osman788b9162020-02-07 10:36:46 -0500615 std::max(1, SkScalarRoundToInt(preScaleW * fscale)),
616 std::max(1, SkScalarRoundToInt(preScaleH * fscale)));
kjlubick2a42f482016-02-16 16:14:23 -0800617 size_t rowBytes = decodeInfo.minRowBytes();
Leon Scroggins571b30f2017-07-11 17:35:31 +0000618 if (!subsetBm.installPixels(decodeInfo, pixels, rowBytes)) {
kjlubick2a42f482016-02-16 16:14:23 -0800619 SkDebugf("[terminated] Could not install pixels.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500620 return;
kjlubick2a42f482016-02-16 16:14:23 -0800621 }
622 const SkCodec::Result result = codec->getPixels(decodeInfo, pixels, rowBytes,
Leon Scroggins571b30f2017-07-11 17:35:31 +0000623 &opts);
kjlubick2a42f482016-02-16 16:14:23 -0800624 switch (result) {
625 case SkCodec::kSuccess:
626 case SkCodec::kIncompleteInput:
Leon Scroggins III674a1842017-07-06 12:26:09 -0400627 case SkCodec::kErrorInInput:
kjlubick2a42f482016-02-16 16:14:23 -0800628 SkDebugf("okay\n");
629 break;
630 case SkCodec::kInvalidConversion:
631 if (0 == (x|y)) {
632 // First subset is okay to return unimplemented.
633 SkDebugf("[terminated] Incompatible colortype conversion\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500634 return;
kjlubick2a42f482016-02-16 16:14:23 -0800635 }
636 // If the first subset succeeded, a later one should not fail.
John Stiles30212b72020-06-11 17:55:07 -0400637 [[fallthrough]];
kjlubick2a42f482016-02-16 16:14:23 -0800638 case SkCodec::kUnimplemented:
639 if (0 == (x|y)) {
640 // First subset is okay to return unimplemented.
641 SkDebugf("[terminated] subset codec not supported\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500642 return;
kjlubick2a42f482016-02-16 16:14:23 -0800643 }
644 // If the first subset succeeded, why would a later one fail?
John Stiles30212b72020-06-11 17:55:07 -0400645 [[fallthrough]];
kjlubick2a42f482016-02-16 16:14:23 -0800646 default:
647 SkDebugf("[terminated] subset codec failed to decode (%d, %d, %d, %d) "
648 "with dimensions (%d x %d)\t error %d\n",
649 x, y, decodeInfo.width(), decodeInfo.height(),
650 W, H, result);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500651 return;
kjlubick2a42f482016-02-16 16:14:23 -0800652 }
kjlubick2a42f482016-02-16 16:14:23 -0800653 }
kjlubick2a42f482016-02-16 16:14:23 -0800654 }
655 SkDebugf("[terminated] Success!\n");
656 break;
657 }
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500658 case 4: { //kAnimated_Mode
659 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
660 if (frameInfos.size() == 0) {
661 SkDebugf("[terminated] Not an animated image\n");
662 break;
663 }
664
665 for (size_t i = 0; i < frameInfos.size(); i++) {
666 options.fFrameIndex = i;
667 auto result = codec->startIncrementalDecode(decodeInfo, bitmap.getPixels(),
668 bitmap.rowBytes(), &options);
669 if (SkCodec::kSuccess != result) {
670 SkDebugf("[terminated] failed to start incremental decode "
John Stiles7bf79992021-06-25 11:05:20 -0400671 "in frame %zu with error %d\n", i, result);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500672 return;
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500673 }
674
675 result = codec->incrementalDecode();
Leon Scroggins III674a1842017-07-06 12:26:09 -0400676 if (result == SkCodec::kIncompleteInput || result == SkCodec::kErrorInInput) {
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500677 SkDebugf("okay\n");
678 // Frames beyond this one will not decode.
679 break;
680 }
681 if (result == SkCodec::kSuccess) {
John Stiles7bf79992021-06-25 11:05:20 -0400682 SkDebugf("okay - decoded frame %zu\n", i);
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500683 } else {
684 SkDebugf("[terminated] incremental decode failed with "
685 "error %d\n", result);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500686 return;
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500687 }
688 }
689 SkDebugf("[terminated] Success!\n");
690 break;
691 }
kjlubickdba57342016-01-21 05:03:28 -0800692 default:
kjlubick2a42f482016-02-16 16:14:23 -0800693 SkDebugf("[terminated] Mode not implemented yet\n");
kjlubickdba57342016-01-21 05:03:28 -0800694 }
695
696 dump_png(bitmap);
mtklein65e58242016-01-13 12:57:57 -0800697}
698
Zepeng Hufcb7ba02020-07-31 17:21:29 +0000699void FuzzSKP(sk_sp<SkData> bytes);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500700static void fuzz_skp(sk_sp<SkData> bytes) {
Zepeng Hufcb7ba02020-07-31 17:21:29 +0000701 FuzzSKP(bytes);
702 SkDebugf("[terminated] Finished SKP\n");
kjlubickdba57342016-01-21 05:03:28 -0800703}
mtklein65e58242016-01-13 12:57:57 -0800704
Kevin Lubickf80f1152017-01-06 08:26:56 -0500705static void fuzz_color_deserialize(sk_sp<SkData> bytes) {
kjlubick3e3c1a52016-06-23 10:49:27 -0700706 sk_sp<SkColorSpace> space(SkColorSpace::Deserialize(bytes->data(), bytes->size()));
707 if (!space) {
708 SkDebugf("[terminated] Couldn't deserialize Colorspace.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500709 return;
kjlubick3e3c1a52016-06-23 10:49:27 -0700710 }
711 SkDebugf("[terminated] Success! deserialized Colorspace.\n");
kjlubick3e3c1a52016-06-23 10:49:27 -0700712}
713
Kevin Lubickf034d112018-02-08 14:31:24 -0500714void FuzzPathDeserialize(SkReadBuffer& buf);
Kevin Lubickc9d28292017-11-09 08:12:56 -0500715
Kevin Lubickf034d112018-02-08 14:31:24 -0500716static void fuzz_path_deserialize(sk_sp<SkData> bytes) {
717 SkReadBuffer buf(bytes->data(), bytes->size());
718 FuzzPathDeserialize(buf);
719 SkDebugf("[terminated] path_deserialize didn't crash!\n");
Kevin Lubickf04c50a2017-01-06 13:48:19 -0500720}
721
Kevin Lubick2541edf2018-01-11 10:27:14 -0500722bool FuzzRegionDeserialize(sk_sp<SkData> bytes);
723
Kevin Lubickedee1ae2017-02-20 17:47:18 -0500724static void fuzz_region_deserialize(sk_sp<SkData> bytes) {
Kevin Lubick2541edf2018-01-11 10:27:14 -0500725 if (!FuzzRegionDeserialize(bytes)) {
Kevin Lubickedee1ae2017-02-20 17:47:18 -0500726 SkDebugf("[terminated] Couldn't initialize SkRegion.\n");
727 return;
728 }
Kevin Lubickedee1ae2017-02-20 17:47:18 -0500729 SkDebugf("[terminated] Success! Initialized SkRegion.\n");
730}
731
Kevin Lubickf034d112018-02-08 14:31:24 -0500732void FuzzTextBlobDeserialize(SkReadBuffer& buf);
733
Kevin Lubickd46e85f2017-11-21 17:13:35 -0500734static void fuzz_textblob_deserialize(sk_sp<SkData> bytes) {
Mike Reedfadbfcd2017-12-06 16:09:20 -0500735 SkReadBuffer buf(bytes->data(), bytes->size());
Kevin Lubickf034d112018-02-08 14:31:24 -0500736 FuzzTextBlobDeserialize(buf);
737 SkDebugf("[terminated] textblob didn't crash!\n");
Kevin Lubickd46e85f2017-11-21 17:13:35 -0500738}
739
Kevin Lubick2541edf2018-01-11 10:27:14 -0500740void FuzzRegionSetPath(Fuzz* fuzz);
741
742static void fuzz_region_set_path(sk_sp<SkData> bytes) {
743 Fuzz fuzz(bytes);
744 FuzzRegionSetPath(&fuzz);
745 SkDebugf("[terminated] region_set_path didn't crash!\n");
746}
747
Kevin Lubickf034d112018-02-08 14:31:24 -0500748void FuzzImageFilterDeserialize(sk_sp<SkData> bytes);
749
Herb Derbya839fc02017-03-16 12:30:43 -0400750static void fuzz_filter_fuzz(sk_sp<SkData> bytes) {
Kevin Lubickf034d112018-02-08 14:31:24 -0500751 FuzzImageFilterDeserialize(bytes);
752 SkDebugf("[terminated] filter_fuzz didn't crash!\n");
Herb Derbya839fc02017-03-16 12:30:43 -0400753}
754
Zepeng Hua5783f32020-07-10 13:36:20 +0000755bool FuzzSkRuntimeEffect(sk_sp<SkData> bytes);
756
757static void fuzz_skruntimeeffect(sk_sp<SkData> bytes) {
758 if (FuzzSkRuntimeEffect(bytes)) {
759 SkDebugf("[terminated] Success! Compiled and Executed sksl code.\n");
760 } else {
761 SkDebugf("[terminated] Could not Compile or Execute sksl code.\n");
762 }
763}
764
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400765bool FuzzSKSL2GLSL(sk_sp<SkData> bytes);
766
Kevin Lubickf80f1152017-01-06 08:26:56 -0500767static void fuzz_sksl2glsl(sk_sp<SkData> bytes) {
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400768 if (FuzzSKSL2GLSL(bytes)) {
769 SkDebugf("[terminated] Success! Compiled input to GLSL.\n");
770 } else {
771 SkDebugf("[terminated] Could not compile input to GLSL.\n");
kjlubicke7195772016-10-18 10:06:24 -0700772 }
kjlubicke7195772016-10-18 10:06:24 -0700773}
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400774
775bool FuzzSKSL2SPIRV(sk_sp<SkData> bytes);
776
777static void fuzz_sksl2spirv(sk_sp<SkData> bytes) {
778 if (FuzzSKSL2SPIRV(bytes)) {
779 SkDebugf("[terminated] Success! Compiled input to SPIRV.\n");
780 } else {
781 SkDebugf("[terminated] Could not compile input to SPIRV.\n");
782 }
783}
784
785bool FuzzSKSL2Metal(sk_sp<SkData> bytes);
786
787static void fuzz_sksl2metal(sk_sp<SkData> bytes) {
788 if (FuzzSKSL2Metal(bytes)) {
Kevin Lubick39cbe462019-03-11 15:38:00 -0400789 SkDebugf("[terminated] Success! Compiled input to Metal.\n");
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400790 } else {
Kevin Lubick39cbe462019-03-11 15:38:00 -0400791 SkDebugf("[terminated] Could not compile input to Metal.\n");
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400792 }
793}
Kevin Lubick0f0a7102019-03-18 16:20:55 -0400794
795bool FuzzSKSL2Pipeline(sk_sp<SkData> bytes);
796
797static void fuzz_sksl2pipeline(sk_sp<SkData> bytes) {
798 if (FuzzSKSL2Pipeline(bytes)) {
799 SkDebugf("[terminated] Success! Compiled input to pipeline stage.\n");
800 } else {
801 SkDebugf("[terminated] Could not compile input to pipeline stage.\n");
802 }
803}
Kevin Lubick2be14d32019-10-21 13:44:48 -0400804
805void FuzzSkDescriptorDeserialize(sk_sp<SkData> bytes);
806
807static void fuzz_skdescriptor_deserialize(sk_sp<SkData> bytes) {
808 FuzzSkDescriptorDeserialize(bytes);
809 SkDebugf("[terminated] Did not crash while deserializing an SkDescriptor.\n");
810}
811