blob: 1a9e7fae9d647c5acc12346cb416e7cb2551f2f5 [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>);
Robert Phillips44b75682021-08-31 22:30:44 +000096static void fuzz_svg_dom(sk_sp<SkData>);
Kevin Lubickd46e85f2017-11-21 17:13:35 -050097static void fuzz_textblob_deserialize(sk_sp<SkData>);
Herb Derbya839fc02017-03-16 12:30:43 -040098
Kevin Lubickfffa6412018-04-23 16:44:55 -040099static void print_api_names();
100
Florin Malita0b0d93d2018-05-04 15:01:03 -0400101#if defined(SK_ENABLE_SKOTTIE)
102static void fuzz_skottie_json(sk_sp<SkData>);
103#endif
104
mtklein65e58242016-01-13 12:57:57 -0800105int main(int argc, char** argv) {
Mike Klein88544fb2019-03-20 10:50:33 -0500106 CommandLineFlags::SetUsage(
107 "Usage: fuzz -t <type> -b <path/to/file> [-n api-to-fuzz]\n"
108 " fuzz -b <path/to/file>\n"
109 "--help lists the valid types. If type is not specified,\n"
110 "fuzz will make a guess based on the name of the file.\n");
111 CommandLineFlags::Parse(argc, argv);
Kevin Lubickd7255a72019-06-03 11:59:23 -0400112 gSkFontMgr_DefaultFactory = &ToolUtils::MakePortableFontMgr;
mtkleinf5e97822016-01-15 06:19:53 -0800113
Kevin Lubickfffa6412018-04-23 16:44:55 -0400114 SkString path = SkString(FLAGS_bytes.isEmpty() ? argv[0] : FLAGS_bytes[0]);
115 SkString type = SkString(FLAGS_type.isEmpty() ? "" : FLAGS_type[0]);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500116
Brian Osmanf4e57372020-07-17 11:37:14 -0400117 int loopCount = std::max(FLAGS_loops, 1);
118
Kevin Lubickfffa6412018-04-23 16:44:55 -0400119 if (!sk_isdir(path.c_str())) {
Brian Osmanf4e57372020-07-17 11:37:14 -0400120 for (int i = 0; i < loopCount; ++i) {
121 int rv = fuzz_file(path, type);
122 if (rv != 0) {
123 return rv;
124 }
125 }
126 return 0;
Kevin Lubickf80f1152017-01-06 08:26:56 -0500127 }
128
Kevin Lubickfffa6412018-04-23 16:44:55 -0400129 SkOSFile::Iter it(path.c_str());
Kevin Lubickf80f1152017-01-06 08:26:56 -0500130 for (SkString file; it.next(&file); ) {
Kevin Lubickfffa6412018-04-23 16:44:55 -0400131 SkString p = SkOSPath::Join(path.c_str(), file.c_str());
Kevin Lubickf80f1152017-01-06 08:26:56 -0500132 SkDebugf("Fuzzing %s\n", p.c_str());
Brian Osmanf4e57372020-07-17 11:37:14 -0400133 for (int i = 0; i < loopCount; ++i) {
134 int rv = fuzz_file(p, type);
135 if (rv != 0) {
136 return rv;
137 }
Kevin Lubickf80f1152017-01-06 08:26:56 -0500138 }
139 }
140 return 0;
141}
142
Kevin Lubickfffa6412018-04-23 16:44:55 -0400143static int fuzz_file(SkString path, SkString type) {
144 sk_sp<SkData> bytes(SkData::MakeFromFileName(path.c_str()));
kjlubickdba57342016-01-21 05:03:28 -0800145 if (!bytes) {
Kevin Lubickfffa6412018-04-23 16:44:55 -0400146 SkDebugf("Could not read %s\n", path.c_str());
Kevin Lubickf80f1152017-01-06 08:26:56 -0500147 return 1;
kjlubickdba57342016-01-21 05:03:28 -0800148 }
mtklein65e58242016-01-13 12:57:57 -0800149
Kevin Lubickfffa6412018-04-23 16:44:55 -0400150 SkString name = SkString(FLAGS_name.isEmpty() ? "" : FLAGS_name[0]);
151
152 if (type.isEmpty()) {
153 type = try_auto_detect(path, &name);
kjlubickdba57342016-01-21 05:03:28 -0800154 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400155
156 if (type.isEmpty()) {
157 SkDebugf("Could not autodetect type of %s\n", path.c_str());
158 return 1;
159 }
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400160 if (type.equals("android_codec")) {
161 fuzz_android_codec(bytes);
162 return 0;
163 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400164 if (type.equals("animated_image_decode")) {
165 fuzz_animated_img(bytes);
166 return 0;
167 }
168 if (type.equals("api")) {
169 fuzz_api(bytes, name);
170 return 0;
171 }
172 if (type.equals("color_deserialize")) {
173 fuzz_color_deserialize(bytes);
174 return 0;
175 }
Florin Malita80452be2018-06-19 11:27:20 -0400176 if (type.equals("filter_fuzz")) {
177 fuzz_filter_fuzz(bytes);
178 return 0;
179 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400180 if (type.equals("image_decode")) {
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400181 fuzz_image_decode(bytes);
182 return 0;
183 }
184 if (type.equals("image_decode_incremental")) {
185 fuzz_image_decode_incremental(bytes);
Kevin Lubickfffa6412018-04-23 16:44:55 -0400186 return 0;
187 }
188 if (type.equals("image_scale")) {
189 uint8_t option = calculate_option(bytes.get());
190 fuzz_img(bytes, option, 0);
191 return 0;
192 }
193 if (type.equals("image_mode")) {
194 uint8_t option = calculate_option(bytes.get());
195 fuzz_img(bytes, 0, option);
196 return 0;
197 }
Florin Malita80452be2018-06-19 11:27:20 -0400198 if (type.equals("json")) {
199 fuzz_json(bytes);
Kevin Lubick9eeede22018-05-03 16:26:10 -0400200 return 0;
201 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400202 if (type.equals("path_deserialize")) {
203 fuzz_path_deserialize(bytes);
204 return 0;
205 }
206 if (type.equals("region_deserialize")) {
207 fuzz_region_deserialize(bytes);
208 return 0;
209 }
210 if (type.equals("region_set_path")) {
211 fuzz_region_set_path(bytes);
212 return 0;
213 }
214 if (type.equals("pipe")) {
Mike Klein60900b52018-09-21 11:19:45 -0400215 SkDebugf("I would prefer not to.\n");
Kevin Lubickfffa6412018-04-23 16:44:55 -0400216 return 0;
217 }
Kevin Lubick2be14d32019-10-21 13:44:48 -0400218 if (type.equals("skdescriptor_deserialize")) {
219 fuzz_skdescriptor_deserialize(bytes);
220 return 0;
221 }
Florin Malita0b0d93d2018-05-04 15:01:03 -0400222#if defined(SK_ENABLE_SKOTTIE)
Kevin Lubick9eeede22018-05-03 16:26:10 -0400223 if (type.equals("skottie_json")) {
224 fuzz_skottie_json(bytes);
Kevin Lubickfffa6412018-04-23 16:44:55 -0400225 return 0;
226 }
Florin Malita0b0d93d2018-05-04 15:01:03 -0400227#endif
Kevin Lubick9eeede22018-05-03 16:26:10 -0400228 if (type.equals("skp")) {
229 fuzz_skp(bytes);
Kevin Lubickfffa6412018-04-23 16:44:55 -0400230 return 0;
231 }
Zepeng Hua5783f32020-07-10 13:36:20 +0000232 if (type.equals("skruntimeeffect")) {
233 fuzz_skruntimeeffect(bytes);
234 return 0;
235 }
Kevin Lubickfffa6412018-04-23 16:44:55 -0400236 if (type.equals("sksl2glsl")) {
237 fuzz_sksl2glsl(bytes);
238 return 0;
239 }
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400240 if (type.equals("sksl2metal")) {
241 fuzz_sksl2metal(bytes);
242 return 0;
243 }
244 if (type.equals("sksl2spirv")) {
245 fuzz_sksl2spirv(bytes);
246 return 0;
247 }
Kevin Lubick0f0a7102019-03-18 16:20:55 -0400248 if (type.equals("sksl2pipeline")) {
249 fuzz_sksl2pipeline(bytes);
250 return 0;
251 }
Zepeng Huedaf3022020-06-12 12:20:59 +0000252 if (type.equals("svg_dom")) {
253 fuzz_svg_dom(bytes);
254 return 0;
255 }
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400256 if (type.equals("textblob")) {
257 fuzz_textblob_deserialize(bytes);
258 return 0;
259 }
Kevin Lubick457fa972018-05-29 09:22:06 -0400260 SkDebugf("Unknown type %s\n", type.c_str());
Mike Klein88544fb2019-03-20 10:50:33 -0500261 CommandLineFlags::PrintUsage();
Kevin Lubick9ff5dc92018-01-09 12:47:33 -0500262 return 1;
kjlubickdba57342016-01-21 05:03:28 -0800263}
264
Kevin Lubickfffa6412018-04-23 16:44:55 -0400265static std::map<std::string, std::string> cf_api_map = {
Zepeng Hu94007012020-07-22 14:37:46 +0000266 {"api_create_ddl", "CreateDDL"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400267 {"api_draw_functions", "DrawFunctions"},
Adlai Hollerccb68662021-02-25 10:28:44 -0500268 {"api_ddl_threading", "DDLThreadingGL"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400269 {"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"},
Weston Tracey1a771fe2021-02-04 11:09:59 -0500277 {"api_skparagraph", "SkParagraph"},
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 Hufcb7ba02020-07-31 17:21:29 +0000298 {"skp", "skp"},
Zepeng Hua5783f32020-07-10 13:36:20 +0000299 {"skruntimeeffect", "skruntimeeffect"},
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400300 {"sksl2glsl", "sksl2glsl"},
301 {"sksl2metal", "sksl2metal"},
302 {"sksl2spirv", "sksl2spirv"},
Kevin Lubick0f0a7102019-03-18 16:20:55 -0400303 {"sksl2pipeline", "sksl2pipeline"},
Kevin Lubickde54d7c2018-09-24 08:48:19 -0400304#if defined(SK_ENABLE_SKOTTIE)
305 {"skottie_json", "skottie_json"},
306#endif
Zepeng Huedaf3022020-06-12 12:20:59 +0000307 {"svg_dom", "svg_dom"},
Kevin Lubickfffa6412018-04-23 16:44:55 -0400308 {"textblob_deserialize", "textblob"}
309};
310
311static SkString try_auto_detect(SkString path, SkString* name) {
312 std::cmatch m;
313 std::regex clusterfuzz("clusterfuzz-testcase(-minimized)?-([a-z0-9_]+)-[\\d]+");
314 std::regex skiafuzzer("(api-)?(\\w+)-[a-f0-9]+");
315
316 if (std::regex_search(path.c_str(), m, clusterfuzz)) {
317 std::string type = m.str(2);
Kevin Lubick6c560552018-06-20 09:29:23 -0400318
319 if (cf_api_map.find(type) != cf_api_map.end()) {
320 *name = SkString(cf_api_map[type].c_str());
321 return SkString("api");
Kevin Lubickfffa6412018-04-23 16:44:55 -0400322 } else {
323 if (cf_map.find(type) != cf_map.end()) {
324 return SkString(cf_map[type].c_str());
325 }
326 }
327 } else if (std::regex_search(path.c_str(), m, skiafuzzer)) {
328 std::string a1 = m.str(1);
329 std::string typeOrName = m.str(2);
330 if (a1.length() > 0) {
331 // it's an api fuzzer
332 *name = SkString(typeOrName.c_str());
333 return SkString("api");
334 } else {
335 return SkString(typeOrName.c_str());
336 }
337 }
338
339 return SkString("");
340}
341
Florin Malita80452be2018-06-19 11:27:20 -0400342void FuzzJSON(sk_sp<SkData> bytes);
Florin Malita7796f002018-06-08 12:25:38 -0400343
Florin Malita80452be2018-06-19 11:27:20 -0400344static void fuzz_json(sk_sp<SkData> bytes){
345 FuzzJSON(bytes);
Florin Malita7796f002018-06-08 12:25:38 -0400346 SkDebugf("[terminated] Done parsing!\n");
347}
Florin Malita7796f002018-06-08 12:25:38 -0400348
Florin Malita0b0d93d2018-05-04 15:01:03 -0400349#if defined(SK_ENABLE_SKOTTIE)
Kevin Lubick9eeede22018-05-03 16:26:10 -0400350void FuzzSkottieJSON(sk_sp<SkData> bytes);
351
352static void fuzz_skottie_json(sk_sp<SkData> bytes){
353 FuzzSkottieJSON(bytes);
354 SkDebugf("[terminated] Done animating!\n");
355}
Florin Malita0b0d93d2018-05-04 15:01:03 -0400356#endif
Kevin Lubick9eeede22018-05-03 16:26:10 -0400357
Zepeng Huedaf3022020-06-12 12:20:59 +0000358void FuzzSVG(sk_sp<SkData> bytes);
359static void fuzz_svg_dom(sk_sp<SkData> bytes){
360 FuzzSVG(bytes);
361 SkDebugf("[terminated] Done DOM!\n");
362}
363
kjlubick2a42f482016-02-16 16:14:23 -0800364// This adds up the first 1024 bytes and returns it as an 8 bit integer. This allows afl-fuzz to
365// deterministically excercise different paths, or *options* (such as different scaling sizes or
366// different image modes) without needing to introduce a parameter. This way we don't need a
367// image_scale1, image_scale2, image_scale4, etc fuzzer, we can just have a image_scale fuzzer.
368// Clients are expected to transform this number into a different range, e.g. with modulo (%).
369static uint8_t calculate_option(SkData* bytes) {
370 uint8_t total = 0;
371 const uint8_t* data = bytes->bytes();
372 for (size_t i = 0; i < 1024 && i < bytes->size(); i++) {
373 total += data[i];
374 }
375 return total;
376}
377
Kevin Lubickfffa6412018-04-23 16:44:55 -0400378static void print_api_names(){
379 SkDebugf("When using --type api, please choose an API to fuzz with --name/-n:\n");
Hal Canary972eba32018-07-30 17:07:07 -0400380 for (const Fuzzable& fuzzable : sk_tools::Registry<Fuzzable>::Range()) {
Kevin Lubickfffa6412018-04-23 16:44:55 -0400381 SkDebugf("\t%s\n", fuzzable.name);
382 }
383}
384
385static void fuzz_api(sk_sp<SkData> bytes, SkString name) {
Hal Canary972eba32018-07-30 17:07:07 -0400386 for (const Fuzzable& fuzzable : sk_tools::Registry<Fuzzable>::Range()) {
Kevin Lubickfffa6412018-04-23 16:44:55 -0400387 if (name.equals(fuzzable.name)) {
mtkleinf5e97822016-01-15 06:19:53 -0800388 SkDebugf("Fuzzing %s...\n", fuzzable.name);
Kevin Lubick1ac8fd22017-03-01 10:42:45 -0500389 Fuzz fuzz(std::move(bytes));
mtklein65e58242016-01-13 12:57:57 -0800390 fuzzable.fn(&fuzz);
kjlubick47d158e2016-02-01 08:23:50 -0800391 SkDebugf("[terminated] Success!\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500392 return;
mtklein65e58242016-01-13 12:57:57 -0800393 }
394 }
mtkleind4387ea2016-01-21 06:13:52 -0800395
Kevin Lubickfffa6412018-04-23 16:44:55 -0400396 print_api_names();
kjlubickdba57342016-01-21 05:03:28 -0800397}
398
399static void dump_png(SkBitmap bitmap) {
400 if (!FLAGS_dump.isEmpty()) {
Mike Kleinea3f0142019-03-20 11:12:10 -0500401 ToolUtils::EncodeImageToFile(FLAGS_dump[0], bitmap, SkEncodedImageFormat::kPNG, 100);
kjlubickdba57342016-01-21 05:03:28 -0800402 SkDebugf("Dumped to %s\n", FLAGS_dump[0]);
403 }
404}
405
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400406bool FuzzAnimatedImage(sk_sp<SkData> bytes);
Kevin Lubick2416f962018-02-12 08:26:39 -0500407
408static void fuzz_animated_img(sk_sp<SkData> bytes) {
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400409 if (FuzzAnimatedImage(bytes)) {
410 SkDebugf("[terminated] Success from decoding/drawing animated image!\n");
411 return;
412 }
413 SkDebugf("[terminated] Could not decode or draw animated image.\n");
Kevin Lubick2416f962018-02-12 08:26:39 -0500414}
415
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400416bool FuzzImageDecode(sk_sp<SkData> bytes);
Kevin Lubick2416f962018-02-12 08:26:39 -0500417
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400418static void fuzz_image_decode(sk_sp<SkData> bytes) {
419 if (FuzzImageDecode(bytes)) {
420 SkDebugf("[terminated] Success from decoding/drawing image!\n");
421 return;
422 }
423 SkDebugf("[terminated] Could not decode or draw image.\n");
Kevin Lubick2416f962018-02-12 08:26:39 -0500424}
425
Kevin Lubick0f3d2a62018-10-17 10:24:44 -0400426bool FuzzIncrementalImageDecode(sk_sp<SkData> bytes);
427
428static void fuzz_image_decode_incremental(sk_sp<SkData> bytes) {
429 if (FuzzIncrementalImageDecode(bytes)) {
430 SkDebugf("[terminated] Success using incremental decode!\n");
431 return;
432 }
433 SkDebugf("[terminated] Could not incrementally decode and image.\n");
434}
435
436bool FuzzAndroidCodec(sk_sp<SkData> bytes, uint8_t sampleSize);
437
438static void fuzz_android_codec(sk_sp<SkData> bytes) {
439 Fuzz fuzz(bytes);
440 uint8_t sampleSize;
441 fuzz.nextRange(&sampleSize, 1, 64);
442 bytes = SkData::MakeSubset(bytes.get(), 1, bytes->size() - 1);
443 if (FuzzAndroidCodec(bytes, sampleSize)) {
444 SkDebugf("[terminated] Success on Android Codec sampleSize=%u!\n", sampleSize);
445 return;
446 }
447 SkDebugf("[terminated] Could not use Android Codec sampleSize=%u!\n", sampleSize);
448}
449
450// This is a "legacy" fuzzer that likely does too much. It was based off of how
451// DM reads in images. image_decode, image_decode_incremental and android_codec
452// are more targeted fuzzers that do a subset of what this one does.
Kevin Lubickf80f1152017-01-06 08:26:56 -0500453static void fuzz_img(sk_sp<SkData> bytes, uint8_t scale, uint8_t mode) {
kjlubick2a42f482016-02-16 16:14:23 -0800454 // We can scale 1x, 2x, 4x, 8x, 16x
455 scale = scale % 5;
kjlubick5bd98a22016-02-18 06:27:38 -0800456 float fscale = (float)pow(2.0f, scale);
457 SkDebugf("Scaling factor: %f\n", fscale);
kjlubick2a42f482016-02-16 16:14:23 -0800458
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500459 // We have 5 different modes of decoding.
460 mode = mode % 5;
kjlubick2a42f482016-02-16 16:14:23 -0800461 SkDebugf("Mode: %d\n", mode);
462
463 // This is mostly copied from DMSrcSink's CodecSrc::draw method.
kjlubick47d158e2016-02-01 08:23:50 -0800464 SkDebugf("Decoding\n");
Mike Reedede7bac2017-07-23 15:30:02 -0400465 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(bytes));
John Stilesa008b0f2020-08-16 08:48:02 -0400466 if (nullptr == codec) {
kjlubick47d158e2016-02-01 08:23:50 -0800467 SkDebugf("[terminated] Couldn't create codec.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500468 return;
kjlubickdba57342016-01-21 05:03:28 -0800469 }
470
471 SkImageInfo decodeInfo = codec->getInfo();
kjlubick2a42f482016-02-16 16:14:23 -0800472 SkISize size = codec->getScaledDimensions(fscale);
Brian Salomon9241a6d2019-10-03 13:26:54 -0400473 decodeInfo = decodeInfo.makeDimensions(size);
kjlubick2a42f482016-02-16 16:14:23 -0800474
kjlubickdba57342016-01-21 05:03:28 -0800475 SkBitmap bitmap;
kjlubickdba57342016-01-21 05:03:28 -0800476 SkCodec::Options options;
477 options.fZeroInitialized = SkCodec::kYes_ZeroInitialized;
478
Mike Reed086a4272017-07-18 10:53:11 -0400479 if (!bitmap.tryAllocPixelsFlags(decodeInfo, SkBitmap::kZeroPixels_AllocFlag)) {
kjlubick47d158e2016-02-01 08:23:50 -0800480 SkDebugf("[terminated] Could not allocate memory. Image might be too large (%d x %d)",
kjlubick2a42f482016-02-16 16:14:23 -0800481 decodeInfo.width(), decodeInfo.height());
Kevin Lubickf80f1152017-01-06 08:26:56 -0500482 return;
kjlubickdba57342016-01-21 05:03:28 -0800483 }
484
kjlubick2a42f482016-02-16 16:14:23 -0800485 switch (mode) {
486 case 0: {//kCodecZeroInit_Mode, kCodec_Mode
Leon Scroggins571b30f2017-07-11 17:35:31 +0000487 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes(), &options)) {
kjlubick2a42f482016-02-16 16:14:23 -0800488 case SkCodec::kSuccess:
489 SkDebugf("[terminated] Success!\n");
490 break;
491 case SkCodec::kIncompleteInput:
492 SkDebugf("[terminated] Partial Success\n");
493 break;
Leon Scroggins III674a1842017-07-06 12:26:09 -0400494 case SkCodec::kErrorInInput:
495 SkDebugf("[terminated] Partial Success with error\n");
496 break;
kjlubick2a42f482016-02-16 16:14:23 -0800497 case SkCodec::kInvalidConversion:
498 SkDebugf("Incompatible colortype conversion\n");
499 // Crash to allow afl-fuzz to know this was a bug.
500 raise(SIGSEGV);
John Stiles30212b72020-06-11 17:55:07 -0400501 break;
kjlubick2a42f482016-02-16 16:14:23 -0800502 default:
503 SkDebugf("[terminated] Couldn't getPixels.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500504 return;
kjlubick2a42f482016-02-16 16:14:23 -0800505 }
506 break;
507 }
508 case 1: {//kScanline_Mode
Leon Scroggins571b30f2017-07-11 17:35:31 +0000509 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo)) {
510 SkDebugf("[terminated] Could not start scanline decoder\n");
511 return;
512 }
kjlubick2a42f482016-02-16 16:14:23 -0800513
514 void* dst = bitmap.getAddr(0, 0);
515 size_t rowBytes = bitmap.rowBytes();
516 uint32_t height = decodeInfo.height();
Brian Osmanea176c62018-04-06 15:28:23 -0400517 // We do not need to check the return value. On an incomplete
518 // image, memory will be filled with a default value.
519 codec->getScanlines(dst, height, rowBytes);
kjlubick47d158e2016-02-01 08:23:50 -0800520 SkDebugf("[terminated] Success!\n");
kjlubickdba57342016-01-21 05:03:28 -0800521 break;
kjlubick2a42f482016-02-16 16:14:23 -0800522 }
523 case 2: { //kStripe_Mode
524 const int height = decodeInfo.height();
525 // This value is chosen arbitrarily. We exercise more cases by choosing a value that
526 // does not align with image blocks.
527 const int stripeHeight = 37;
528 const int numStripes = (height + stripeHeight - 1) / stripeHeight;
529
530 // Decode odd stripes
Leon Scroggins571b30f2017-07-11 17:35:31 +0000531 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo)
kjlubick2a42f482016-02-16 16:14:23 -0800532 || SkCodec::kTopDown_SkScanlineOrder != codec->getScanlineOrder()) {
533 // This mode was designed to test the new skip scanlines API in libjpeg-turbo.
534 // Jpegs have kTopDown_SkScanlineOrder, and at this time, it is not interesting
535 // to run this test for image types that do not have this scanline ordering.
536 SkDebugf("[terminated] Could not start top-down scanline decoder\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500537 return;
kjlubick2a42f482016-02-16 16:14:23 -0800538 }
539
540 for (int i = 0; i < numStripes; i += 2) {
541 // Skip a stripe
Brian Osman788b9162020-02-07 10:36:46 -0500542 const int linesToSkip = std::min(stripeHeight, height - i * stripeHeight);
kjlubick2a42f482016-02-16 16:14:23 -0800543 codec->skipScanlines(linesToSkip);
544
545 // Read a stripe
546 const int startY = (i + 1) * stripeHeight;
Brian Osman788b9162020-02-07 10:36:46 -0500547 const int linesToRead = std::min(stripeHeight, height - startY);
kjlubick2a42f482016-02-16 16:14:23 -0800548 if (linesToRead > 0) {
549 codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitmap.rowBytes());
550 }
551 }
552
553 // Decode even stripes
Leon Scroggins571b30f2017-07-11 17:35:31 +0000554 const SkCodec::Result startResult = codec->startScanlineDecode(decodeInfo);
kjlubick2a42f482016-02-16 16:14:23 -0800555 if (SkCodec::kSuccess != startResult) {
556 SkDebugf("[terminated] Failed to restart scanline decoder with same parameters.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500557 return;
kjlubick2a42f482016-02-16 16:14:23 -0800558 }
559 for (int i = 0; i < numStripes; i += 2) {
560 // Read a stripe
561 const int startY = i * stripeHeight;
Brian Osman788b9162020-02-07 10:36:46 -0500562 const int linesToRead = std::min(stripeHeight, height - startY);
kjlubick2a42f482016-02-16 16:14:23 -0800563 codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitmap.rowBytes());
564
565 // Skip a stripe
Brian Osman788b9162020-02-07 10:36:46 -0500566 const int linesToSkip = std::min(stripeHeight, height - (i + 1) * stripeHeight);
kjlubick2a42f482016-02-16 16:14:23 -0800567 if (linesToSkip > 0) {
568 codec->skipScanlines(linesToSkip);
569 }
570 }
571 SkDebugf("[terminated] Success!\n");
kjlubickdba57342016-01-21 05:03:28 -0800572 break;
kjlubick2a42f482016-02-16 16:14:23 -0800573 }
574 case 3: { //kSubset_Mode
575 // Arbitrarily choose a divisor.
576 int divisor = 2;
577 // Total width/height of the image.
578 const int W = codec->getInfo().width();
579 const int H = codec->getInfo().height();
580 if (divisor > W || divisor > H) {
581 SkDebugf("[terminated] Cannot codec subset: divisor %d is too big "
582 "with dimensions (%d x %d)\n", divisor, W, H);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500583 return;
kjlubick2a42f482016-02-16 16:14:23 -0800584 }
585 // subset dimensions
586 // SkWebpCodec, the only one that supports subsets, requires even top/left boundaries.
587 const int w = SkAlign2(W / divisor);
588 const int h = SkAlign2(H / divisor);
589 SkIRect subset;
590 SkCodec::Options opts;
591 opts.fSubset = &subset;
592 SkBitmap subsetBm;
593 // We will reuse pixel memory from bitmap.
594 void* pixels = bitmap.getPixels();
kjlubick2a42f482016-02-16 16:14:23 -0800595 for (int x = 0; x < W; x += w) {
kjlubick2a42f482016-02-16 16:14:23 -0800596 for (int y = 0; y < H; y+= h) {
597 // Do not make the subset go off the edge of the image.
Brian Osman788b9162020-02-07 10:36:46 -0500598 const int preScaleW = std::min(w, W - x);
599 const int preScaleH = std::min(h, H - y);
kjlubick2a42f482016-02-16 16:14:23 -0800600 subset.setXYWH(x, y, preScaleW, preScaleH);
601 // And fscale
602 // FIXME: Should we have a version of getScaledDimensions that takes a subset
603 // into account?
604 decodeInfo = decodeInfo.makeWH(
Brian Osman788b9162020-02-07 10:36:46 -0500605 std::max(1, SkScalarRoundToInt(preScaleW * fscale)),
606 std::max(1, SkScalarRoundToInt(preScaleH * fscale)));
kjlubick2a42f482016-02-16 16:14:23 -0800607 size_t rowBytes = decodeInfo.minRowBytes();
Leon Scroggins571b30f2017-07-11 17:35:31 +0000608 if (!subsetBm.installPixels(decodeInfo, pixels, rowBytes)) {
kjlubick2a42f482016-02-16 16:14:23 -0800609 SkDebugf("[terminated] Could not install pixels.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500610 return;
kjlubick2a42f482016-02-16 16:14:23 -0800611 }
612 const SkCodec::Result result = codec->getPixels(decodeInfo, pixels, rowBytes,
Leon Scroggins571b30f2017-07-11 17:35:31 +0000613 &opts);
kjlubick2a42f482016-02-16 16:14:23 -0800614 switch (result) {
615 case SkCodec::kSuccess:
616 case SkCodec::kIncompleteInput:
Leon Scroggins III674a1842017-07-06 12:26:09 -0400617 case SkCodec::kErrorInInput:
kjlubick2a42f482016-02-16 16:14:23 -0800618 SkDebugf("okay\n");
619 break;
620 case SkCodec::kInvalidConversion:
621 if (0 == (x|y)) {
622 // First subset is okay to return unimplemented.
623 SkDebugf("[terminated] Incompatible colortype conversion\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500624 return;
kjlubick2a42f482016-02-16 16:14:23 -0800625 }
626 // If the first subset succeeded, a later one should not fail.
John Stiles30212b72020-06-11 17:55:07 -0400627 [[fallthrough]];
kjlubick2a42f482016-02-16 16:14:23 -0800628 case SkCodec::kUnimplemented:
629 if (0 == (x|y)) {
630 // First subset is okay to return unimplemented.
631 SkDebugf("[terminated] subset codec not supported\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500632 return;
kjlubick2a42f482016-02-16 16:14:23 -0800633 }
634 // If the first subset succeeded, why would a later one fail?
John Stiles30212b72020-06-11 17:55:07 -0400635 [[fallthrough]];
kjlubick2a42f482016-02-16 16:14:23 -0800636 default:
637 SkDebugf("[terminated] subset codec failed to decode (%d, %d, %d, %d) "
638 "with dimensions (%d x %d)\t error %d\n",
639 x, y, decodeInfo.width(), decodeInfo.height(),
640 W, H, result);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500641 return;
kjlubick2a42f482016-02-16 16:14:23 -0800642 }
kjlubick2a42f482016-02-16 16:14:23 -0800643 }
kjlubick2a42f482016-02-16 16:14:23 -0800644 }
645 SkDebugf("[terminated] Success!\n");
646 break;
647 }
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500648 case 4: { //kAnimated_Mode
649 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
650 if (frameInfos.size() == 0) {
651 SkDebugf("[terminated] Not an animated image\n");
652 break;
653 }
654
655 for (size_t i = 0; i < frameInfos.size(); i++) {
656 options.fFrameIndex = i;
657 auto result = codec->startIncrementalDecode(decodeInfo, bitmap.getPixels(),
658 bitmap.rowBytes(), &options);
659 if (SkCodec::kSuccess != result) {
660 SkDebugf("[terminated] failed to start incremental decode "
John Stiles7bf79992021-06-25 11:05:20 -0400661 "in frame %zu with error %d\n", i, result);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500662 return;
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500663 }
664
665 result = codec->incrementalDecode();
Leon Scroggins III674a1842017-07-06 12:26:09 -0400666 if (result == SkCodec::kIncompleteInput || result == SkCodec::kErrorInInput) {
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500667 SkDebugf("okay\n");
668 // Frames beyond this one will not decode.
669 break;
670 }
671 if (result == SkCodec::kSuccess) {
John Stiles7bf79992021-06-25 11:05:20 -0400672 SkDebugf("okay - decoded frame %zu\n", i);
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500673 } else {
674 SkDebugf("[terminated] incremental decode failed with "
675 "error %d\n", result);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500676 return;
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500677 }
678 }
679 SkDebugf("[terminated] Success!\n");
680 break;
681 }
kjlubickdba57342016-01-21 05:03:28 -0800682 default:
kjlubick2a42f482016-02-16 16:14:23 -0800683 SkDebugf("[terminated] Mode not implemented yet\n");
kjlubickdba57342016-01-21 05:03:28 -0800684 }
685
686 dump_png(bitmap);
mtklein65e58242016-01-13 12:57:57 -0800687}
688
Zepeng Hufcb7ba02020-07-31 17:21:29 +0000689void FuzzSKP(sk_sp<SkData> bytes);
Kevin Lubickf80f1152017-01-06 08:26:56 -0500690static void fuzz_skp(sk_sp<SkData> bytes) {
Zepeng Hufcb7ba02020-07-31 17:21:29 +0000691 FuzzSKP(bytes);
692 SkDebugf("[terminated] Finished SKP\n");
kjlubickdba57342016-01-21 05:03:28 -0800693}
mtklein65e58242016-01-13 12:57:57 -0800694
Kevin Lubickf80f1152017-01-06 08:26:56 -0500695static void fuzz_color_deserialize(sk_sp<SkData> bytes) {
kjlubick3e3c1a52016-06-23 10:49:27 -0700696 sk_sp<SkColorSpace> space(SkColorSpace::Deserialize(bytes->data(), bytes->size()));
697 if (!space) {
698 SkDebugf("[terminated] Couldn't deserialize Colorspace.\n");
Kevin Lubickf80f1152017-01-06 08:26:56 -0500699 return;
kjlubick3e3c1a52016-06-23 10:49:27 -0700700 }
701 SkDebugf("[terminated] Success! deserialized Colorspace.\n");
kjlubick3e3c1a52016-06-23 10:49:27 -0700702}
703
Kevin Lubickf034d112018-02-08 14:31:24 -0500704void FuzzPathDeserialize(SkReadBuffer& buf);
Kevin Lubickc9d28292017-11-09 08:12:56 -0500705
Kevin Lubickf034d112018-02-08 14:31:24 -0500706static void fuzz_path_deserialize(sk_sp<SkData> bytes) {
707 SkReadBuffer buf(bytes->data(), bytes->size());
708 FuzzPathDeserialize(buf);
709 SkDebugf("[terminated] path_deserialize didn't crash!\n");
Kevin Lubickf04c50a2017-01-06 13:48:19 -0500710}
711
Kevin Lubick2541edf2018-01-11 10:27:14 -0500712bool FuzzRegionDeserialize(sk_sp<SkData> bytes);
713
Kevin Lubickedee1ae2017-02-20 17:47:18 -0500714static void fuzz_region_deserialize(sk_sp<SkData> bytes) {
Kevin Lubick2541edf2018-01-11 10:27:14 -0500715 if (!FuzzRegionDeserialize(bytes)) {
Kevin Lubickedee1ae2017-02-20 17:47:18 -0500716 SkDebugf("[terminated] Couldn't initialize SkRegion.\n");
717 return;
718 }
Kevin Lubickedee1ae2017-02-20 17:47:18 -0500719 SkDebugf("[terminated] Success! Initialized SkRegion.\n");
720}
721
Kevin Lubickf034d112018-02-08 14:31:24 -0500722void FuzzTextBlobDeserialize(SkReadBuffer& buf);
723
Kevin Lubickd46e85f2017-11-21 17:13:35 -0500724static void fuzz_textblob_deserialize(sk_sp<SkData> bytes) {
Mike Reedfadbfcd2017-12-06 16:09:20 -0500725 SkReadBuffer buf(bytes->data(), bytes->size());
Kevin Lubickf034d112018-02-08 14:31:24 -0500726 FuzzTextBlobDeserialize(buf);
727 SkDebugf("[terminated] textblob didn't crash!\n");
Kevin Lubickd46e85f2017-11-21 17:13:35 -0500728}
729
Kevin Lubick2541edf2018-01-11 10:27:14 -0500730void FuzzRegionSetPath(Fuzz* fuzz);
731
732static void fuzz_region_set_path(sk_sp<SkData> bytes) {
733 Fuzz fuzz(bytes);
734 FuzzRegionSetPath(&fuzz);
735 SkDebugf("[terminated] region_set_path didn't crash!\n");
736}
737
Kevin Lubickf034d112018-02-08 14:31:24 -0500738void FuzzImageFilterDeserialize(sk_sp<SkData> bytes);
739
Herb Derbya839fc02017-03-16 12:30:43 -0400740static void fuzz_filter_fuzz(sk_sp<SkData> bytes) {
Kevin Lubickf034d112018-02-08 14:31:24 -0500741 FuzzImageFilterDeserialize(bytes);
742 SkDebugf("[terminated] filter_fuzz didn't crash!\n");
Herb Derbya839fc02017-03-16 12:30:43 -0400743}
744
Zepeng Hua5783f32020-07-10 13:36:20 +0000745bool FuzzSkRuntimeEffect(sk_sp<SkData> bytes);
746
747static void fuzz_skruntimeeffect(sk_sp<SkData> bytes) {
748 if (FuzzSkRuntimeEffect(bytes)) {
749 SkDebugf("[terminated] Success! Compiled and Executed sksl code.\n");
750 } else {
751 SkDebugf("[terminated] Could not Compile or Execute sksl code.\n");
752 }
753}
754
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400755bool FuzzSKSL2GLSL(sk_sp<SkData> bytes);
756
Kevin Lubickf80f1152017-01-06 08:26:56 -0500757static void fuzz_sksl2glsl(sk_sp<SkData> bytes) {
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400758 if (FuzzSKSL2GLSL(bytes)) {
759 SkDebugf("[terminated] Success! Compiled input to GLSL.\n");
760 } else {
761 SkDebugf("[terminated] Could not compile input to GLSL.\n");
kjlubicke7195772016-10-18 10:06:24 -0700762 }
kjlubicke7195772016-10-18 10:06:24 -0700763}
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400764
765bool FuzzSKSL2SPIRV(sk_sp<SkData> bytes);
766
767static void fuzz_sksl2spirv(sk_sp<SkData> bytes) {
768 if (FuzzSKSL2SPIRV(bytes)) {
769 SkDebugf("[terminated] Success! Compiled input to SPIRV.\n");
770 } else {
771 SkDebugf("[terminated] Could not compile input to SPIRV.\n");
772 }
773}
774
775bool FuzzSKSL2Metal(sk_sp<SkData> bytes);
776
777static void fuzz_sksl2metal(sk_sp<SkData> bytes) {
778 if (FuzzSKSL2Metal(bytes)) {
Kevin Lubick39cbe462019-03-11 15:38:00 -0400779 SkDebugf("[terminated] Success! Compiled input to Metal.\n");
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400780 } else {
Kevin Lubick39cbe462019-03-11 15:38:00 -0400781 SkDebugf("[terminated] Could not compile input to Metal.\n");
Kevin Lubicke9c1ce82019-03-11 11:09:40 -0400782 }
783}
Kevin Lubick0f0a7102019-03-18 16:20:55 -0400784
785bool FuzzSKSL2Pipeline(sk_sp<SkData> bytes);
786
787static void fuzz_sksl2pipeline(sk_sp<SkData> bytes) {
788 if (FuzzSKSL2Pipeline(bytes)) {
789 SkDebugf("[terminated] Success! Compiled input to pipeline stage.\n");
790 } else {
791 SkDebugf("[terminated] Could not compile input to pipeline stage.\n");
792 }
793}
Kevin Lubick2be14d32019-10-21 13:44:48 -0400794
795void FuzzSkDescriptorDeserialize(sk_sp<SkData> bytes);
796
797static void fuzz_skdescriptor_deserialize(sk_sp<SkData> bytes) {
798 FuzzSkDescriptorDeserialize(bytes);
799 SkDebugf("[terminated] Did not crash while deserializing an SkDescriptor.\n");
800}
801