blob: 055850ece1e944954343b7c56b35b1600dbe9fd5 [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"
22#include "src/core/SkPicturePriv.h"
23#include "src/core/SkReadBuffer.h"
24#include "src/utils/SkOSPath.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050025#include "tools/ToolUtils.h"
Kevin Lubickd7255a72019-06-03 11:59:23 -040026#include "tools/flags/CommandLineFlags.h"
27#include "tools/fonts/TestFontMgr.h"
Hal Canary8a001442018-09-19 11:31:27 -040028
Hal Canary62176db2017-02-27 16:42:03 -050029#include <iostream>
Kevin Lubickacd456a2018-04-24 13:58:16 -040030#include <map>
Kevin Lubickfffa6412018-04-23 16:44:55 -040031#include <regex>
mtkleina1159422016-01-15 05:46:54 -080032#include <signal.h>
Kevin Lubick2541edf2018-01-11 10:27:14 -050033
Mike Klein84836b72019-03-21 11:31:36 -050034static DEFINE_string2(bytes, b, "", "A path to a file or a directory. If a file, the "
35 "contents will be used as the fuzz bytes. If a directory, all files "
36 "in the directory will be used as fuzz bytes for the fuzzer, one at a "
37 "time.");
38static DEFINE_string2(name, n, "", "If --type is 'api', fuzz the API with this name.");
39static DEFINE_string2(dump, d, "", "If not empty, dump 'image*' or 'skp' types as a "
40 "PNG with this name.");
Brian Osmanf4e57372020-07-17 11:37:14 -040041static DEFINE_int(loops, 1, "Run the fuzzer on each input this many times.");
Kevin Lubick9ff5dc92018-01-09 12:47:33 -050042DEFINE_bool2(verbose, v, false, "Print more information while fuzzing.");
Florin Malita7796f002018-06-08 12:25:38 -040043
44// This cannot be inlined in DEFINE_string2 due to interleaved ifdefs
45static constexpr char g_type_message[] = "How to interpret --bytes, one of:\n"
Kevin Lubick0f3d2a62018-10-17 10:24:44 -040046 "android_codec\n"
Florin Malita7796f002018-06-08 12:25:38 -040047 "animated_image_decode\n"
48 "api\n"
49 "color_deserialize\n"
50 "filter_fuzz (equivalent to Chrome's filter_fuzz_stub)\n"
51 "image_decode\n"
Kevin Lubick0f3d2a62018-10-17 10:24:44 -040052 "image_decode_incremental\n"
Florin Malita7796f002018-06-08 12:25:38 -040053 "image_mode\n"
54 "image_scale\n"
Florin Malita80452be2018-06-19 11:27:20 -040055 "json\n"
Florin Malita7796f002018-06-08 12:25:38 -040056 "path_deserialize\n"
Florin Malita7796f002018-06-08 12:25:38 -040057 "region_deserialize\n"
58 "region_set_path\n"
Kevin Lubick2be14d32019-10-21 13:44:48 -040059 "skdescriptor_deserialize\n"
Florin Malita7796f002018-06-08 12:25:38 -040060 "skp\n"
Zepeng Hua5783f32020-07-10 13:36:20 +000061 "skruntimeeffect\n"
Florin Malita7796f002018-06-08 12:25:38 -040062 "sksl2glsl\n"
Zepeng Huedaf3022020-06-12 12:20:59 +000063 "svg_dom\n"
Kevin Lubicke9c1ce82019-03-11 11:09:40 -040064 "sksl2metal\n"
Kevin Lubick0f0a7102019-03-18 16:20:55 -040065 "sksl2pipeline\n"
Kevin Lubicke9c1ce82019-03-11 11:09:40 -040066 "sksl2spirv\n"
Florin Malita7796f002018-06-08 12:25:38 -040067#if defined(SK_ENABLE_SKOTTIE)
68 "skottie_json\n"
69#endif
70 "textblob";
71
Mike Klein84836b72019-03-21 11:31:36 -050072static DEFINE_string2(type, t, "", g_type_message);
kjlubickdba57342016-01-21 05:03:28 -080073
Kevin Lubickfffa6412018-04-23 16:44:55 -040074static int fuzz_file(SkString path, SkString type);
kjlubick2a42f482016-02-16 16:14:23 -080075static uint8_t calculate_option(SkData*);
Kevin Lubickfffa6412018-04-23 16:44:55 -040076static SkString try_auto_detect(SkString path, SkString* name);
kjlubickdba57342016-01-21 05:03:28 -080077
Kevin Lubick0f3d2a62018-10-17 10:24:44 -040078static void fuzz_android_codec(sk_sp<SkData>);
79static void fuzz_animated_img(sk_sp<SkData>);
Kevin Lubickfffa6412018-04-23 16:44:55 -040080static void fuzz_api(sk_sp<SkData> bytes, SkString name);
Kevin Lubickf80f1152017-01-06 08:26:56 -050081static void fuzz_color_deserialize(sk_sp<SkData>);
Kevin Lubickd46e85f2017-11-21 17:13:35 -050082static void fuzz_filter_fuzz(sk_sp<SkData>);
Kevin Lubick0f3d2a62018-10-17 10:24:44 -040083static void fuzz_image_decode(sk_sp<SkData>);
84static void fuzz_image_decode_incremental(sk_sp<SkData>);
Kevin Lubick0168e042017-02-14 13:12:37 -050085static void fuzz_img(sk_sp<SkData>, uint8_t, uint8_t);
Florin Malita80452be2018-06-19 11:27:20 -040086static void fuzz_json(sk_sp<SkData>);
Kevin Lubickf04c50a2017-01-06 13:48:19 -050087static void fuzz_path_deserialize(sk_sp<SkData>);
Kevin Lubickedee1ae2017-02-20 17:47:18 -050088static void fuzz_region_deserialize(sk_sp<SkData>);
Kevin Lubick2541edf2018-01-11 10:27:14 -050089static void fuzz_region_set_path(sk_sp<SkData>);
Kevin Lubick2be14d32019-10-21 13:44:48 -040090static void fuzz_skdescriptor_deserialize(sk_sp<SkData>);
Kevin Lubick0168e042017-02-14 13:12:37 -050091static void fuzz_skp(sk_sp<SkData>);
Zepeng Hua5783f32020-07-10 13:36:20 +000092static void fuzz_skruntimeeffect(sk_sp<SkData>);
Kevin Lubicke9c1ce82019-03-11 11:09:40 -040093static void fuzz_sksl2glsl(sk_sp<SkData>);
94static void fuzz_sksl2metal(sk_sp<SkData>);
Kevin Lubick0f0a7102019-03-18 16:20:55 -040095static void fuzz_sksl2pipeline(sk_sp<SkData>);
Kevin Lubick2be14d32019-10-21 13:44:48 -040096static void fuzz_sksl2spirv(sk_sp<SkData>);
Zepeng Huedaf3022020-06-12 12:20:59 +000097static void fuzz_svg_dom(sk_sp<SkData>);
Kevin Lubickd46e85f2017-11-21 17:13:35 -050098static void fuzz_textblob_deserialize(sk_sp<SkData>);
Herb Derbya839fc02017-03-16 12:30:43 -040099
Kevin Lubickfffa6412018-04-23 16:44:55 -0400100static void print_api_names();
101
Florin Malita0b0d93d2018-05-04 15:01:03 -0400102#if defined(SK_ENABLE_SKOTTIE)
103static void fuzz_skottie_json(sk_sp<SkData>);
104#endif
105
mtklein65e58242016-01-13 12:57:57 -0800106int main(int argc, char** argv) {
Mike Klein88544fb2019-03-20 10:50:33 -0500107 CommandLineFlags::SetUsage(
108 "Usage: fuzz -t <type> -b <path/to/file> [-n api-to-fuzz]\n"
109 " fuzz -b <path/to/file>\n"
110 "--help lists the valid types. If type is not specified,\n"
111 "fuzz will make a guess based on the name of the file.\n");
112 CommandLineFlags::Parse(argc, argv);
Kevin Lubickd7255a72019-06-03 11:59:23 -0400113 gSkFontMgr_DefaultFactory = &ToolUtils::MakePortableFontMgr;
mtkleinf5e97822016-01-15 06:19:53 -0800114
Kevin Lubickfffa6412018-04-23 16:44:55 -0400115 SkString path = SkString(FLAGS_bytes.isEmpty() ? argv[0] : FLAGS_bytes[0]);
116 SkString type = SkString(FLAGS_type.isEmpty() ? "" : FLAGS_type[0]);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500117
Brian Osmanf4e57372020-07-17 11:37:14 -0400118 int loopCount = std::max(FLAGS_loops, 1);
119
Kevin Lubickfffa6412018-04-23 16:44:55 -0400120 if (!sk_isdir(path.c_str())) {
Brian Osmanf4e57372020-07-17 11:37:14 -0400121 for (int i = 0; i < loopCount; ++i) {
122 int rv = fuzz_file(path, type);
123 if (rv != 0) {
124 return rv;
125 }
126 }
127 return 0;
Kevin Lubickf80f1152017-01-06 08:26:56 -0500128 }
129
Kevin Lubickfffa6412018-04-23 16:44:55 -0400130 SkOSFile::Iter it(path.c_str());
Kevin Lubickf80f1152017-01-06 08:26:56 -0500131 for (SkString file; it.next(&file); ) {
Kevin Lubickfffa6412018-04-23 16:44:55 -0400132 SkString p = SkOSPath::Join(path.c_str(), file.c_str());
Kevin Lubickf80f1152017-01-06 08:26:56 -0500133 SkDebugf("Fuzzing %s\n", p.c_str());
Brian Osmanf4e57372020-07-17 11:37:14 -0400134 for (int i = 0; i < loopCount; ++i) {
135 int rv = fuzz_file(p, type);
136 if (rv != 0) {
137 return rv;
138 }
Kevin Lubickf80f1152017-01-06 08:26:56 -0500139 }
140 }
141 return 0;
142}
143
Kevin Lubickfffa6412018-04-23 16:44:55 -0400144static int fuzz_file(SkString path, SkString type) {
145 sk_sp<SkData> bytes(SkData::MakeFromFileName(path.c_str()));
kjlubickdba57342016-01-21 05:03:28 -0800146 if (!bytes) {
Kevin Lubickfffa6412018-04-23 16:44:55 -0400147 SkDebugf("Could not read %s\n", path.c_str());
Kevin Lubickf80f1152017-01-06 08:26:56 -0500148 return 1;
kjlubickdba57342016-01-21 05:03:28 -0800149 }
mtklein65e58242016-01-13 12:57:57 -0800150
Kevin Lubickfffa6412018-04-23 16:44:55 -0400151 SkString name = SkString(FLAGS_name.isEmpty() ? "" : FLAGS_name[0]);
152
153 if (type.isEmpty()) {
154 type = try_auto_detect(path, &name);
kjlubickdba57342016-01-21 05:03:28 -0800155 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400156
157 if (type.isEmpty()) {
158 SkDebugf("Could not autodetect type of %s\n", path.c_str());
159 return 1;
160 }
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400161 if (type.equals("android_codec")) {
162 fuzz_android_codec(bytes);
163 return 0;
164 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400165 if (type.equals("animated_image_decode")) {
166 fuzz_animated_img(bytes);
167 return 0;
168 }
169 if (type.equals("api")) {
170 fuzz_api(bytes, name);
171 return 0;
172 }
173 if (type.equals("color_deserialize")) {
174 fuzz_color_deserialize(bytes);
175 return 0;
176 }
Florin Malita80452be2018-06-19 11:27:20 -0400177 if (type.equals("filter_fuzz")) {
178 fuzz_filter_fuzz(bytes);
179 return 0;
180 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400181 if (type.equals("image_decode")) {
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400182 fuzz_image_decode(bytes);
183 return 0;
184 }
185 if (type.equals("image_decode_incremental")) {
186 fuzz_image_decode_incremental(bytes);
Kevin Lubickfffa6412018-04-23 16:44:55 -0400187 return 0;
188 }
189 if (type.equals("image_scale")) {
190 uint8_t option = calculate_option(bytes.get());
191 fuzz_img(bytes, option, 0);
192 return 0;
193 }
194 if (type.equals("image_mode")) {
195 uint8_t option = calculate_option(bytes.get());
196 fuzz_img(bytes, 0, option);
197 return 0;
198 }
Florin Malita80452be2018-06-19 11:27:20 -0400199 if (type.equals("json")) {
200 fuzz_json(bytes);
Kevin Lubick9eeede22018-05-03 16:26:10 -0400201 return 0;
202 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400203 if (type.equals("path_deserialize")) {
204 fuzz_path_deserialize(bytes);
205 return 0;
206 }
207 if (type.equals("region_deserialize")) {
208 fuzz_region_deserialize(bytes);
209 return 0;
210 }
211 if (type.equals("region_set_path")) {
212 fuzz_region_set_path(bytes);
213 return 0;
214 }
215 if (type.equals("pipe")) {
Mike Klein60900b52018-09-21 11:19:45 -0400216 SkDebugf("I would prefer not to.\n");
Kevin Lubickfffa6412018-04-23 16:44:55 -0400217 return 0;
218 }
Kevin Lubick2be14d32019-10-21 13:44:48 -0400219 if (type.equals("skdescriptor_deserialize")) {
220 fuzz_skdescriptor_deserialize(bytes);
221 return 0;
222 }
Florin Malita0b0d93d2018-05-04 15:01:03 -0400223#if defined(SK_ENABLE_SKOTTIE)
Kevin Lubick9eeede22018-05-03 16:26:10 -0400224 if (type.equals("skottie_json")) {
225 fuzz_skottie_json(bytes);
Kevin Lubickfffa6412018-04-23 16:44:55 -0400226 return 0;
227 }
Florin Malita0b0d93d2018-05-04 15:01:03 -0400228#endif
Kevin Lubick9eeede22018-05-03 16:26:10 -0400229 if (type.equals("skp")) {
230 fuzz_skp(bytes);
Kevin Lubickfffa6412018-04-23 16:44:55 -0400231 return 0;
232 }
Zepeng Hua5783f32020-07-10 13:36:20 +0000233 if (type.equals("skruntimeeffect")) {
234 fuzz_skruntimeeffect(bytes);
235 return 0;
236 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400237 if (type.equals("sksl2glsl")) {
238 fuzz_sksl2glsl(bytes);
239 return 0;
240 }
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400241 if (type.equals("sksl2metal")) {
242 fuzz_sksl2metal(bytes);
243 return 0;
244 }
245 if (type.equals("sksl2spirv")) {
246 fuzz_sksl2spirv(bytes);
247 return 0;
248 }
Kevin Lubick0f0a7102019-03-18 16:20:55 -0400249 if (type.equals("sksl2pipeline")) {
250 fuzz_sksl2pipeline(bytes);
251 return 0;
252 }
Zepeng Huedaf3022020-06-12 12:20:59 +0000253 if (type.equals("svg_dom")) {
254 fuzz_svg_dom(bytes);
255 return 0;
256 }
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400257 if (type.equals("textblob")) {
258 fuzz_textblob_deserialize(bytes);
259 return 0;
260 }
Kevin Lubick457fa972018-05-29 09:22:06 -0400261 SkDebugf("Unknown type %s\n", type.c_str());
Mike Klein88544fb2019-03-20 10:50:33 -0500262 CommandLineFlags::PrintUsage();
Kevin Lubick9ff5dc92018-01-09 12:47:33 -0500263 return 1;
kjlubickdba57342016-01-21 05:03:28 -0800264}
265
Kevin Lubickfffa6412018-04-23 16:44:55 -0400266static std::map<std::string, std::string> cf_api_map = {
Zepeng Hu94007012020-07-22 14:37:46 +0000267 {"api_create_ddl", "CreateDDL"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400268 {"api_draw_functions", "DrawFunctions"},
269 {"api_gradients", "Gradients"},
270 {"api_image_filter", "ImageFilter"},
271 {"api_mock_gpu_canvas", "MockGPUCanvas"},
272 {"api_null_canvas", "NullCanvas"},
273 {"api_path_measure", "PathMeasure"},
Kevin Lubickde54d7c2018-09-24 08:48:19 -0400274 {"api_pathop", "Pathop"},
Kevin Lubick57507f12018-10-11 09:35:15 -0400275 {"api_polyutils", "PolyUtils"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400276 {"api_raster_n32_canvas", "RasterN32Canvas"},
Kevin Lubick2be14d32019-10-21 13:44:48 -0400277 {"api_skdescriptor", "SkDescriptor"},
Zepeng Huba7cbf72020-07-01 13:21:03 +0000278 {"api_svg_canvas", "SVGCanvas"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400279 {"jpeg_encoder", "JPEGEncoder"},
280 {"png_encoder", "PNGEncoder"},
Kevin Lubickf84ded22018-10-23 09:28:48 -0400281 {"skia_pathop_fuzzer", "LegacyChromiumPathop"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400282 {"webp_encoder", "WEBPEncoder"}
283};
284
Kevin Lubick6c560552018-06-20 09:29:23 -0400285// maps clusterfuzz/oss-fuzz -> Skia's name
Kevin Lubickfffa6412018-04-23 16:44:55 -0400286static std::map<std::string, std::string> cf_map = {
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400287 {"android_codec", "android_codec"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400288 {"animated_image_decode", "animated_image_decode"},
289 {"image_decode", "image_decode"},
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400290 {"image_decode_incremental", "image_decode_incremental"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400291 {"image_filter_deserialize", "filter_fuzz"},
292 {"image_filter_deserialize_width", "filter_fuzz"},
293 {"path_deserialize", "path_deserialize"},
294 {"region_deserialize", "region_deserialize"},
295 {"region_set_path", "region_set_path"},
Kevin Lubick2be14d32019-10-21 13:44:48 -0400296 {"skdescriptor_deserialize", "skdescriptor_deserialize"},
Kevin Lubick6c560552018-06-20 09:29:23 -0400297 {"skjson", "json"},
Zepeng Hua5783f32020-07-10 13:36:20 +0000298 {"skruntimeeffect", "skruntimeeffect"},
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400299 {"sksl2glsl", "sksl2glsl"},
300 {"sksl2metal", "sksl2metal"},
301 {"sksl2spirv", "sksl2spirv"},
Kevin Lubick0f0a7102019-03-18 16:20:55 -0400302 {"sksl2pipeline", "sksl2pipeline"},
Kevin Lubickde54d7c2018-09-24 08:48:19 -0400303#if defined(SK_ENABLE_SKOTTIE)
304 {"skottie_json", "skottie_json"},
305#endif
Zepeng Huedaf3022020-06-12 12:20:59 +0000306 {"svg_dom", "svg_dom"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400307 {"textblob_deserialize", "textblob"}
308};
309
310static SkString try_auto_detect(SkString path, SkString* name) {
311 std::cmatch m;
312 std::regex clusterfuzz("clusterfuzz-testcase(-minimized)?-([a-z0-9_]+)-[\\d]+");
313 std::regex skiafuzzer("(api-)?(\\w+)-[a-f0-9]+");
314
315 if (std::regex_search(path.c_str(), m, clusterfuzz)) {
316 std::string type = m.str(2);
Kevin Lubick6c560552018-06-20 09:29:23 -0400317
318 if (cf_api_map.find(type) != cf_api_map.end()) {
319 *name = SkString(cf_api_map[type].c_str());
320 return SkString("api");
Kevin Lubickfffa6412018-04-23 16:44:55 -0400321 } else {
322 if (cf_map.find(type) != cf_map.end()) {
323 return SkString(cf_map[type].c_str());
324 }
325 }
326 } else if (std::regex_search(path.c_str(), m, skiafuzzer)) {
327 std::string a1 = m.str(1);
328 std::string typeOrName = m.str(2);
329 if (a1.length() > 0) {
330 // it's an api fuzzer
331 *name = SkString(typeOrName.c_str());
332 return SkString("api");
333 } else {
334 return SkString(typeOrName.c_str());
335 }
336 }
337
338 return SkString("");
339}
340
Florin Malita80452be2018-06-19 11:27:20 -0400341void FuzzJSON(sk_sp<SkData> bytes);
Florin Malita7796f002018-06-08 12:25:38 -0400342
Florin Malita80452be2018-06-19 11:27:20 -0400343static void fuzz_json(sk_sp<SkData> bytes){
344 FuzzJSON(bytes);
Florin Malita7796f002018-06-08 12:25:38 -0400345 SkDebugf("[terminated] Done parsing!\n");
346}
Florin Malita7796f002018-06-08 12:25:38 -0400347
Florin Malita0b0d93d2018-05-04 15:01:03 -0400348#if defined(SK_ENABLE_SKOTTIE)
Kevin Lubick9eeede22018-05-03 16:26:10 -0400349void FuzzSkottieJSON(sk_sp<SkData> bytes);
350
351static void fuzz_skottie_json(sk_sp<SkData> bytes){
352 FuzzSkottieJSON(bytes);
353 SkDebugf("[terminated] Done animating!\n");
354}
Florin Malita0b0d93d2018-05-04 15:01:03 -0400355#endif
Kevin Lubick9eeede22018-05-03 16:26:10 -0400356
Zepeng Huedaf3022020-06-12 12:20:59 +0000357void FuzzSVG(sk_sp<SkData> bytes);
358static void fuzz_svg_dom(sk_sp<SkData> bytes){
359 FuzzSVG(bytes);
360 SkDebugf("[terminated] Done DOM!\n");
361}
362
kjlubick2a42f482016-02-16 16:14:23 -0800363// This adds up the first 1024 bytes and returns it as an 8 bit integer. This allows afl-fuzz to
364// deterministically excercise different paths, or *options* (such as different scaling sizes or
365// different image modes) without needing to introduce a parameter. This way we don't need a
366// image_scale1, image_scale2, image_scale4, etc fuzzer, we can just have a image_scale fuzzer.
367// Clients are expected to transform this number into a different range, e.g. with modulo (%).
368static uint8_t calculate_option(SkData* bytes) {
369 uint8_t total = 0;
370 const uint8_t* data = bytes->bytes();
371 for (size_t i = 0; i < 1024 && i < bytes->size(); i++) {
372 total += data[i];
373 }
374 return total;
375}
376
Kevin Lubickfffa6412018-04-23 16:44:55 -0400377static void print_api_names(){
378 SkDebugf("When using --type api, please choose an API to fuzz with --name/-n:\n");
Hal Canary972eba32018-07-30 17:07:07 -0400379 for (const Fuzzable& fuzzable : sk_tools::Registry<Fuzzable>::Range()) {
Kevin Lubickfffa6412018-04-23 16:44:55 -0400380 SkDebugf("\t%s\n", fuzzable.name);
381 }
382}
383
384static void fuzz_api(sk_sp<SkData> bytes, SkString name) {
Hal Canary972eba32018-07-30 17:07:07 -0400385 for (const Fuzzable& fuzzable : sk_tools::Registry<Fuzzable>::Range()) {
Kevin Lubickfffa6412018-04-23 16:44:55 -0400386 if (name.equals(fuzzable.name)) {
mtkleinf5e97822016-01-15 06:19:53 -0800387 SkDebugf("Fuzzing %s...\n", fuzzable.name);
Kevin Lubick1ac8fd22017-03-01 10:42:45 -0500388 Fuzz fuzz(std::move(bytes));
mtklein65e58242016-01-13 12:57:57 -0800389 fuzzable.fn(&fuzz);
kjlubick47d158e2016-02-01 08:23:50 -0800390 SkDebugf("[terminated] Success!\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500391 return;
mtklein65e58242016-01-13 12:57:57 -0800392 }
393 }
mtkleind4387ea2016-01-21 06:13:52 -0800394
Kevin Lubickfffa6412018-04-23 16:44:55 -0400395 print_api_names();
kjlubickdba57342016-01-21 05:03:28 -0800396}
397
398static void dump_png(SkBitmap bitmap) {
399 if (!FLAGS_dump.isEmpty()) {
Mike Kleinea3f0142019-03-20 11:12:10 -0500400 ToolUtils::EncodeImageToFile(FLAGS_dump[0], bitmap, SkEncodedImageFormat::kPNG, 100);
kjlubickdba57342016-01-21 05:03:28 -0800401 SkDebugf("Dumped to %s\n", FLAGS_dump[0]);
402 }
403}
404
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400405bool FuzzAnimatedImage(sk_sp<SkData> bytes);
Kevin Lubick2416f962018-02-12 08:26:39 -0500406
407static void fuzz_animated_img(sk_sp<SkData> bytes) {
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400408 if (FuzzAnimatedImage(bytes)) {
409 SkDebugf("[terminated] Success from decoding/drawing animated image!\n");
410 return;
411 }
412 SkDebugf("[terminated] Could not decode or draw animated image.\n");
Kevin Lubick2416f962018-02-12 08:26:39 -0500413}
414
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400415bool FuzzImageDecode(sk_sp<SkData> bytes);
Kevin Lubick2416f962018-02-12 08:26:39 -0500416
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400417static void fuzz_image_decode(sk_sp<SkData> bytes) {
418 if (FuzzImageDecode(bytes)) {
419 SkDebugf("[terminated] Success from decoding/drawing image!\n");
420 return;
421 }
422 SkDebugf("[terminated] Could not decode or draw image.\n");
Kevin Lubick2416f962018-02-12 08:26:39 -0500423}
424
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400425bool FuzzIncrementalImageDecode(sk_sp<SkData> bytes);
426
427static void fuzz_image_decode_incremental(sk_sp<SkData> bytes) {
428 if (FuzzIncrementalImageDecode(bytes)) {
429 SkDebugf("[terminated] Success using incremental decode!\n");
430 return;
431 }
432 SkDebugf("[terminated] Could not incrementally decode and image.\n");
433}
434
435bool FuzzAndroidCodec(sk_sp<SkData> bytes, uint8_t sampleSize);
436
437static void fuzz_android_codec(sk_sp<SkData> bytes) {
438 Fuzz fuzz(bytes);
439 uint8_t sampleSize;
440 fuzz.nextRange(&sampleSize, 1, 64);
441 bytes = SkData::MakeSubset(bytes.get(), 1, bytes->size() - 1);
442 if (FuzzAndroidCodec(bytes, sampleSize)) {
443 SkDebugf("[terminated] Success on Android Codec sampleSize=%u!\n", sampleSize);
444 return;
445 }
446 SkDebugf("[terminated] Could not use Android Codec sampleSize=%u!\n", sampleSize);
447}
448
449// This is a "legacy" fuzzer that likely does too much. It was based off of how
450// DM reads in images. image_decode, image_decode_incremental and android_codec
451// are more targeted fuzzers that do a subset of what this one does.
Kevin Lubickf80f1152017-01-06 08:26:56 -0500452static void fuzz_img(sk_sp<SkData> bytes, uint8_t scale, uint8_t mode) {
kjlubick2a42f482016-02-16 16:14:23 -0800453 // We can scale 1x, 2x, 4x, 8x, 16x
454 scale = scale % 5;
kjlubick5bd98a22016-02-18 06:27:38 -0800455 float fscale = (float)pow(2.0f, scale);
456 SkDebugf("Scaling factor: %f\n", fscale);
kjlubick2a42f482016-02-16 16:14:23 -0800457
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500458 // We have 5 different modes of decoding.
459 mode = mode % 5;
kjlubick2a42f482016-02-16 16:14:23 -0800460 SkDebugf("Mode: %d\n", mode);
461
462 // This is mostly copied from DMSrcSink's CodecSrc::draw method.
kjlubick47d158e2016-02-01 08:23:50 -0800463 SkDebugf("Decoding\n");
Mike Reedede7bac2017-07-23 15:30:02 -0400464 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(bytes));
kjlubickdba57342016-01-21 05:03:28 -0800465 if (nullptr == codec.get()) {
kjlubick47d158e2016-02-01 08:23:50 -0800466 SkDebugf("[terminated] Couldn't create codec.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500467 return;
kjlubickdba57342016-01-21 05:03:28 -0800468 }
469
470 SkImageInfo decodeInfo = codec->getInfo();
kjlubick2a42f482016-02-16 16:14:23 -0800471 SkISize size = codec->getScaledDimensions(fscale);
Brian Salomon9241a6d2019-10-03 13:26:54 -0400472 decodeInfo = decodeInfo.makeDimensions(size);
kjlubick2a42f482016-02-16 16:14:23 -0800473
kjlubickdba57342016-01-21 05:03:28 -0800474 SkBitmap bitmap;
kjlubickdba57342016-01-21 05:03:28 -0800475 SkCodec::Options options;
476 options.fZeroInitialized = SkCodec::kYes_ZeroInitialized;
477
Mike Reed086a4272017-07-18 10:53:11 -0400478 if (!bitmap.tryAllocPixelsFlags(decodeInfo, SkBitmap::kZeroPixels_AllocFlag)) {
kjlubick47d158e2016-02-01 08:23:50 -0800479 SkDebugf("[terminated] Could not allocate memory. Image might be too large (%d x %d)",
kjlubick2a42f482016-02-16 16:14:23 -0800480 decodeInfo.width(), decodeInfo.height());
Kevin Lubickf80f1152017-01-06 08:26:56 -0500481 return;
kjlubickdba57342016-01-21 05:03:28 -0800482 }
483
kjlubick2a42f482016-02-16 16:14:23 -0800484 switch (mode) {
485 case 0: {//kCodecZeroInit_Mode, kCodec_Mode
Leon Scroggins571b30f2017-07-11 17:35:31 +0000486 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes(), &options)) {
kjlubick2a42f482016-02-16 16:14:23 -0800487 case SkCodec::kSuccess:
488 SkDebugf("[terminated] Success!\n");
489 break;
490 case SkCodec::kIncompleteInput:
491 SkDebugf("[terminated] Partial Success\n");
492 break;
Leon Scroggins III674a1842017-07-06 12:26:09 -0400493 case SkCodec::kErrorInInput:
494 SkDebugf("[terminated] Partial Success with error\n");
495 break;
kjlubick2a42f482016-02-16 16:14:23 -0800496 case SkCodec::kInvalidConversion:
497 SkDebugf("Incompatible colortype conversion\n");
498 // Crash to allow afl-fuzz to know this was a bug.
499 raise(SIGSEGV);
John Stiles30212b72020-06-11 17:55:07 -0400500 break;
kjlubick2a42f482016-02-16 16:14:23 -0800501 default:
502 SkDebugf("[terminated] Couldn't getPixels.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500503 return;
kjlubick2a42f482016-02-16 16:14:23 -0800504 }
505 break;
506 }
507 case 1: {//kScanline_Mode
Leon Scroggins571b30f2017-07-11 17:35:31 +0000508 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo)) {
509 SkDebugf("[terminated] Could not start scanline decoder\n");
510 return;
511 }
kjlubick2a42f482016-02-16 16:14:23 -0800512
513 void* dst = bitmap.getAddr(0, 0);
514 size_t rowBytes = bitmap.rowBytes();
515 uint32_t height = decodeInfo.height();
Brian Osmanea176c62018-04-06 15:28:23 -0400516 // We do not need to check the return value. On an incomplete
517 // image, memory will be filled with a default value.
518 codec->getScanlines(dst, height, rowBytes);
kjlubick47d158e2016-02-01 08:23:50 -0800519 SkDebugf("[terminated] Success!\n");
kjlubickdba57342016-01-21 05:03:28 -0800520 break;
kjlubick2a42f482016-02-16 16:14:23 -0800521 }
522 case 2: { //kStripe_Mode
523 const int height = decodeInfo.height();
524 // This value is chosen arbitrarily. We exercise more cases by choosing a value that
525 // does not align with image blocks.
526 const int stripeHeight = 37;
527 const int numStripes = (height + stripeHeight - 1) / stripeHeight;
528
529 // Decode odd stripes
Leon Scroggins571b30f2017-07-11 17:35:31 +0000530 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo)
kjlubick2a42f482016-02-16 16:14:23 -0800531 || SkCodec::kTopDown_SkScanlineOrder != codec->getScanlineOrder()) {
532 // This mode was designed to test the new skip scanlines API in libjpeg-turbo.
533 // Jpegs have kTopDown_SkScanlineOrder, and at this time, it is not interesting
534 // to run this test for image types that do not have this scanline ordering.
535 SkDebugf("[terminated] Could not start top-down scanline decoder\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500536 return;
kjlubick2a42f482016-02-16 16:14:23 -0800537 }
538
539 for (int i = 0; i < numStripes; i += 2) {
540 // Skip a stripe
Brian Osman788b9162020-02-07 10:36:46 -0500541 const int linesToSkip = std::min(stripeHeight, height - i * stripeHeight);
kjlubick2a42f482016-02-16 16:14:23 -0800542 codec->skipScanlines(linesToSkip);
543
544 // Read a stripe
545 const int startY = (i + 1) * stripeHeight;
Brian Osman788b9162020-02-07 10:36:46 -0500546 const int linesToRead = std::min(stripeHeight, height - startY);
kjlubick2a42f482016-02-16 16:14:23 -0800547 if (linesToRead > 0) {
548 codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitmap.rowBytes());
549 }
550 }
551
552 // Decode even stripes
Leon Scroggins571b30f2017-07-11 17:35:31 +0000553 const SkCodec::Result startResult = codec->startScanlineDecode(decodeInfo);
kjlubick2a42f482016-02-16 16:14:23 -0800554 if (SkCodec::kSuccess != startResult) {
555 SkDebugf("[terminated] Failed to restart scanline decoder with same parameters.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500556 return;
kjlubick2a42f482016-02-16 16:14:23 -0800557 }
558 for (int i = 0; i < numStripes; i += 2) {
559 // Read a stripe
560 const int startY = i * stripeHeight;
Brian Osman788b9162020-02-07 10:36:46 -0500561 const int linesToRead = std::min(stripeHeight, height - startY);
kjlubick2a42f482016-02-16 16:14:23 -0800562 codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitmap.rowBytes());
563
564 // Skip a stripe
Brian Osman788b9162020-02-07 10:36:46 -0500565 const int linesToSkip = std::min(stripeHeight, height - (i + 1) * stripeHeight);
kjlubick2a42f482016-02-16 16:14:23 -0800566 if (linesToSkip > 0) {
567 codec->skipScanlines(linesToSkip);
568 }
569 }
570 SkDebugf("[terminated] Success!\n");
kjlubickdba57342016-01-21 05:03:28 -0800571 break;
kjlubick2a42f482016-02-16 16:14:23 -0800572 }
573 case 3: { //kSubset_Mode
574 // Arbitrarily choose a divisor.
575 int divisor = 2;
576 // Total width/height of the image.
577 const int W = codec->getInfo().width();
578 const int H = codec->getInfo().height();
579 if (divisor > W || divisor > H) {
580 SkDebugf("[terminated] Cannot codec subset: divisor %d is too big "
581 "with dimensions (%d x %d)\n", divisor, W, H);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500582 return;
kjlubick2a42f482016-02-16 16:14:23 -0800583 }
584 // subset dimensions
585 // SkWebpCodec, the only one that supports subsets, requires even top/left boundaries.
586 const int w = SkAlign2(W / divisor);
587 const int h = SkAlign2(H / divisor);
588 SkIRect subset;
589 SkCodec::Options opts;
590 opts.fSubset = &subset;
591 SkBitmap subsetBm;
592 // We will reuse pixel memory from bitmap.
593 void* pixels = bitmap.getPixels();
594 // Keep track of left and top (for drawing subsetBm into canvas). We could use
595 // fscale * x and fscale * y, but we want integers such that the next subset will start
596 // where the last one ended. So we'll add decodeInfo.width() and height().
597 int left = 0;
598 for (int x = 0; x < W; x += w) {
599 int top = 0;
600 for (int y = 0; y < H; y+= h) {
601 // Do not make the subset go off the edge of the image.
Brian Osman788b9162020-02-07 10:36:46 -0500602 const int preScaleW = std::min(w, W - x);
603 const int preScaleH = std::min(h, H - y);
kjlubick2a42f482016-02-16 16:14:23 -0800604 subset.setXYWH(x, y, preScaleW, preScaleH);
605 // And fscale
606 // FIXME: Should we have a version of getScaledDimensions that takes a subset
607 // into account?
608 decodeInfo = decodeInfo.makeWH(
Brian Osman788b9162020-02-07 10:36:46 -0500609 std::max(1, SkScalarRoundToInt(preScaleW * fscale)),
610 std::max(1, SkScalarRoundToInt(preScaleH * fscale)));
kjlubick2a42f482016-02-16 16:14:23 -0800611 size_t rowBytes = decodeInfo.minRowBytes();
Leon Scroggins571b30f2017-07-11 17:35:31 +0000612 if (!subsetBm.installPixels(decodeInfo, pixels, rowBytes)) {
kjlubick2a42f482016-02-16 16:14:23 -0800613 SkDebugf("[terminated] Could not install pixels.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500614 return;
kjlubick2a42f482016-02-16 16:14:23 -0800615 }
616 const SkCodec::Result result = codec->getPixels(decodeInfo, pixels, rowBytes,
Leon Scroggins571b30f2017-07-11 17:35:31 +0000617 &opts);
kjlubick2a42f482016-02-16 16:14:23 -0800618 switch (result) {
619 case SkCodec::kSuccess:
620 case SkCodec::kIncompleteInput:
Leon Scroggins III674a1842017-07-06 12:26:09 -0400621 case SkCodec::kErrorInInput:
kjlubick2a42f482016-02-16 16:14:23 -0800622 SkDebugf("okay\n");
623 break;
624 case SkCodec::kInvalidConversion:
625 if (0 == (x|y)) {
626 // First subset is okay to return unimplemented.
627 SkDebugf("[terminated] Incompatible colortype conversion\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500628 return;
kjlubick2a42f482016-02-16 16:14:23 -0800629 }
630 // If the first subset succeeded, a later one should not fail.
John Stiles30212b72020-06-11 17:55:07 -0400631 [[fallthrough]];
kjlubick2a42f482016-02-16 16:14:23 -0800632 case SkCodec::kUnimplemented:
633 if (0 == (x|y)) {
634 // First subset is okay to return unimplemented.
635 SkDebugf("[terminated] subset codec not supported\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500636 return;
kjlubick2a42f482016-02-16 16:14:23 -0800637 }
638 // If the first subset succeeded, why would a later one fail?
John Stiles30212b72020-06-11 17:55:07 -0400639 [[fallthrough]];
kjlubick2a42f482016-02-16 16:14:23 -0800640 default:
641 SkDebugf("[terminated] subset codec failed to decode (%d, %d, %d, %d) "
642 "with dimensions (%d x %d)\t error %d\n",
643 x, y, decodeInfo.width(), decodeInfo.height(),
644 W, H, result);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500645 return;
kjlubick2a42f482016-02-16 16:14:23 -0800646 }
647 // translate by the scaled height.
648 top += decodeInfo.height();
649 }
650 // translate by the scaled width.
651 left += decodeInfo.width();
652 }
653 SkDebugf("[terminated] Success!\n");
654 break;
655 }
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500656 case 4: { //kAnimated_Mode
657 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
658 if (frameInfos.size() == 0) {
659 SkDebugf("[terminated] Not an animated image\n");
660 break;
661 }
662
663 for (size_t i = 0; i < frameInfos.size(); i++) {
664 options.fFrameIndex = i;
665 auto result = codec->startIncrementalDecode(decodeInfo, bitmap.getPixels(),
666 bitmap.rowBytes(), &options);
667 if (SkCodec::kSuccess != result) {
668 SkDebugf("[terminated] failed to start incremental decode "
669 "in frame %d with error %d\n", i, result);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500670 return;
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500671 }
672
673 result = codec->incrementalDecode();
Leon Scroggins III674a1842017-07-06 12:26:09 -0400674 if (result == SkCodec::kIncompleteInput || result == SkCodec::kErrorInInput) {
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500675 SkDebugf("okay\n");
676 // Frames beyond this one will not decode.
677 break;
678 }
679 if (result == SkCodec::kSuccess) {
680 SkDebugf("okay - decoded frame %d\n", i);
681 } else {
682 SkDebugf("[terminated] incremental decode failed with "
683 "error %d\n", result);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500684 return;
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500685 }
686 }
687 SkDebugf("[terminated] Success!\n");
688 break;
689 }
kjlubickdba57342016-01-21 05:03:28 -0800690 default:
kjlubick2a42f482016-02-16 16:14:23 -0800691 SkDebugf("[terminated] Mode not implemented yet\n");
kjlubickdba57342016-01-21 05:03:28 -0800692 }
693
694 dump_png(bitmap);
mtklein65e58242016-01-13 12:57:57 -0800695}
696
Kevin Lubickf80f1152017-01-06 08:26:56 -0500697static void fuzz_skp(sk_sp<SkData> bytes) {
Kevin Lubick09757b22017-12-12 12:52:39 -0500698 SkReadBuffer buf(bytes->data(), bytes->size());
kjlubickdba57342016-01-21 05:03:28 -0800699 SkDebugf("Decoding\n");
Cary Clarkefd99cc2018-06-11 16:25:43 -0400700 sk_sp<SkPicture> pic(SkPicturePriv::MakeFromBuffer(buf));
kjlubickdba57342016-01-21 05:03:28 -0800701 if (!pic) {
kjlubick47d158e2016-02-01 08:23:50 -0800702 SkDebugf("[terminated] Couldn't decode as a picture.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500703 return;
kjlubickdba57342016-01-21 05:03:28 -0800704 }
705 SkDebugf("Rendering\n");
706 SkBitmap bitmap;
707 if (!FLAGS_dump.isEmpty()) {
708 SkIRect size = pic->cullRect().roundOut();
709 bitmap.allocN32Pixels(size.width(), size.height());
710 }
711 SkCanvas canvas(bitmap);
712 canvas.drawPicture(pic);
kjlubick47d158e2016-02-01 08:23:50 -0800713 SkDebugf("[terminated] Success! Decoded and rendered an SkPicture!\n");
kjlubickdba57342016-01-21 05:03:28 -0800714 dump_png(bitmap);
kjlubickdba57342016-01-21 05:03:28 -0800715}
mtklein65e58242016-01-13 12:57:57 -0800716
Kevin Lubickf80f1152017-01-06 08:26:56 -0500717static void fuzz_color_deserialize(sk_sp<SkData> bytes) {
kjlubick3e3c1a52016-06-23 10:49:27 -0700718 sk_sp<SkColorSpace> space(SkColorSpace::Deserialize(bytes->data(), bytes->size()));
719 if (!space) {
720 SkDebugf("[terminated] Couldn't deserialize Colorspace.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500721 return;
kjlubick3e3c1a52016-06-23 10:49:27 -0700722 }
723 SkDebugf("[terminated] Success! deserialized Colorspace.\n");
kjlubick3e3c1a52016-06-23 10:49:27 -0700724}
725
Kevin Lubickf034d112018-02-08 14:31:24 -0500726void FuzzPathDeserialize(SkReadBuffer& buf);
Kevin Lubickc9d28292017-11-09 08:12:56 -0500727
Kevin Lubickf034d112018-02-08 14:31:24 -0500728static void fuzz_path_deserialize(sk_sp<SkData> bytes) {
729 SkReadBuffer buf(bytes->data(), bytes->size());
730 FuzzPathDeserialize(buf);
731 SkDebugf("[terminated] path_deserialize didn't crash!\n");
Kevin Lubickf04c50a2017-01-06 13:48:19 -0500732}
733
Kevin Lubick2541edf2018-01-11 10:27:14 -0500734bool FuzzRegionDeserialize(sk_sp<SkData> bytes);
735
Kevin Lubickedee1ae2017-02-20 17:47:18 -0500736static void fuzz_region_deserialize(sk_sp<SkData> bytes) {
Kevin Lubick2541edf2018-01-11 10:27:14 -0500737 if (!FuzzRegionDeserialize(bytes)) {
Kevin Lubickedee1ae2017-02-20 17:47:18 -0500738 SkDebugf("[terminated] Couldn't initialize SkRegion.\n");
739 return;
740 }
Kevin Lubickedee1ae2017-02-20 17:47:18 -0500741 SkDebugf("[terminated] Success! Initialized SkRegion.\n");
742}
743
Kevin Lubickf034d112018-02-08 14:31:24 -0500744void FuzzTextBlobDeserialize(SkReadBuffer& buf);
745
Kevin Lubickd46e85f2017-11-21 17:13:35 -0500746static void fuzz_textblob_deserialize(sk_sp<SkData> bytes) {
Mike Reedfadbfcd2017-12-06 16:09:20 -0500747 SkReadBuffer buf(bytes->data(), bytes->size());
Kevin Lubickf034d112018-02-08 14:31:24 -0500748 FuzzTextBlobDeserialize(buf);
749 SkDebugf("[terminated] textblob didn't crash!\n");
Kevin Lubickd46e85f2017-11-21 17:13:35 -0500750}
751
Kevin Lubick2541edf2018-01-11 10:27:14 -0500752void FuzzRegionSetPath(Fuzz* fuzz);
753
754static void fuzz_region_set_path(sk_sp<SkData> bytes) {
755 Fuzz fuzz(bytes);
756 FuzzRegionSetPath(&fuzz);
757 SkDebugf("[terminated] region_set_path didn't crash!\n");
758}
759
Kevin Lubickf034d112018-02-08 14:31:24 -0500760void FuzzImageFilterDeserialize(sk_sp<SkData> bytes);
761
Herb Derbya839fc02017-03-16 12:30:43 -0400762static void fuzz_filter_fuzz(sk_sp<SkData> bytes) {
Kevin Lubickf034d112018-02-08 14:31:24 -0500763 FuzzImageFilterDeserialize(bytes);
764 SkDebugf("[terminated] filter_fuzz didn't crash!\n");
Herb Derbya839fc02017-03-16 12:30:43 -0400765}
766
Zepeng Hua5783f32020-07-10 13:36:20 +0000767bool FuzzSkRuntimeEffect(sk_sp<SkData> bytes);
768
769static void fuzz_skruntimeeffect(sk_sp<SkData> bytes) {
770 if (FuzzSkRuntimeEffect(bytes)) {
771 SkDebugf("[terminated] Success! Compiled and Executed sksl code.\n");
772 } else {
773 SkDebugf("[terminated] Could not Compile or Execute sksl code.\n");
774 }
775}
776
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400777bool FuzzSKSL2GLSL(sk_sp<SkData> bytes);
778
Kevin Lubickf80f1152017-01-06 08:26:56 -0500779static void fuzz_sksl2glsl(sk_sp<SkData> bytes) {
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400780 if (FuzzSKSL2GLSL(bytes)) {
781 SkDebugf("[terminated] Success! Compiled input to GLSL.\n");
782 } else {
783 SkDebugf("[terminated] Could not compile input to GLSL.\n");
kjlubicke7195772016-10-18 10:06:24 -0700784 }
kjlubicke7195772016-10-18 10:06:24 -0700785}
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400786
787bool FuzzSKSL2SPIRV(sk_sp<SkData> bytes);
788
789static void fuzz_sksl2spirv(sk_sp<SkData> bytes) {
790 if (FuzzSKSL2SPIRV(bytes)) {
791 SkDebugf("[terminated] Success! Compiled input to SPIRV.\n");
792 } else {
793 SkDebugf("[terminated] Could not compile input to SPIRV.\n");
794 }
795}
796
797bool FuzzSKSL2Metal(sk_sp<SkData> bytes);
798
799static void fuzz_sksl2metal(sk_sp<SkData> bytes) {
800 if (FuzzSKSL2Metal(bytes)) {
Kevin Lubick39cbe462019-03-11 15:38:00 -0400801 SkDebugf("[terminated] Success! Compiled input to Metal.\n");
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400802 } else {
Kevin Lubick39cbe462019-03-11 15:38:00 -0400803 SkDebugf("[terminated] Could not compile input to Metal.\n");
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400804 }
805}
Kevin Lubick0f0a7102019-03-18 16:20:55 -0400806
807bool FuzzSKSL2Pipeline(sk_sp<SkData> bytes);
808
809static void fuzz_sksl2pipeline(sk_sp<SkData> bytes) {
810 if (FuzzSKSL2Pipeline(bytes)) {
811 SkDebugf("[terminated] Success! Compiled input to pipeline stage.\n");
812 } else {
813 SkDebugf("[terminated] Could not compile input to pipeline stage.\n");
814 }
815}
Kevin Lubick2be14d32019-10-21 13:44:48 -0400816
817void FuzzSkDescriptorDeserialize(sk_sp<SkData> bytes);
818
819static void fuzz_skdescriptor_deserialize(sk_sp<SkData> bytes) {
820 FuzzSkDescriptorDeserialize(bytes);
821 SkDebugf("[terminated] Did not crash while deserializing an SkDescriptor.\n");
822}
823