blob: 047bcd88567a273ec5095bae6ef601a909df4d6b [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
8#include "Fuzz.h"
kjlubickdba57342016-01-21 05:03:28 -08009#include "SkCanvas.h"
10#include "SkCodec.h"
mtkleinf5e97822016-01-15 06:19:53 -080011#include "SkCommandLineFlags.h"
kjlubickdba57342016-01-21 05:03:28 -080012#include "SkData.h"
kjlubickdba57342016-01-21 05:03:28 -080013#include "SkImage.h"
14#include "SkImageEncoder.h"
15#include "SkMallocPixelRef.h"
16#include "SkPicture.h"
kjlubicke5654502016-07-19 16:50:03 -070017#include "SkPicture.h"
18#include "SkPicture.h"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050019#if SK_SUPPORT_GPU
kjlubicke7195772016-10-18 10:06:24 -070020#include "SkSLCompiler.h"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050021#endif
kjlubickdba57342016-01-21 05:03:28 -080022#include "SkStream.h"
23
mtkleina1159422016-01-15 05:46:54 -080024#include <signal.h>
mtkleinf5e97822016-01-15 06:19:53 -080025
Hal Canarydb683012016-11-23 08:55:18 -070026#include "sk_tool_utils.h"
27
kjlubickdba57342016-01-21 05:03:28 -080028DEFINE_string2(bytes, b, "", "A path to a file. This can be the fuzz bytes or a binary to parse.");
mtkleind4387ea2016-01-21 06:13:52 -080029DEFINE_string2(name, n, "", "If --type is 'api', fuzz the API with this name.");
kjlubickdba57342016-01-21 05:03:28 -080030
kjlubick897a8e32016-06-09 07:15:12 -070031DEFINE_string2(type, t, "api", "How to interpret --bytes, either 'image_scale', 'image_mode', 'skp', 'icc', or 'api'.");
kjlubick2a42f482016-02-16 16:14:23 -080032DEFINE_string2(dump, d, "", "If not empty, dump 'image*' or 'skp' types as a PNG with this name.");
kjlubickdba57342016-01-21 05:03:28 -080033
34static int printUsage(const char* name) {
mtkleind4387ea2016-01-21 06:13:52 -080035 SkDebugf("Usage: %s -t <type> -b <path/to/file> [-n api-to-fuzz]\n", name);
kjlubickdba57342016-01-21 05:03:28 -080036 return 1;
37}
kjlubick2a42f482016-02-16 16:14:23 -080038static uint8_t calculate_option(SkData*);
kjlubickdba57342016-01-21 05:03:28 -080039
reed42943c82016-09-12 12:01:44 -070040static int fuzz_api(sk_sp<SkData>);
41static int fuzz_img(sk_sp<SkData>, uint8_t, uint8_t);
42static int fuzz_skp(sk_sp<SkData>);
43static int fuzz_icc(sk_sp<SkData>);
44static int fuzz_color_deserialize(sk_sp<SkData>);
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050045#if SK_SUPPORT_GPU
kjlubicke7195772016-10-18 10:06:24 -070046static int fuzz_sksl2glsl(sk_sp<SkData>);
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050047#endif
mtklein65e58242016-01-13 12:57:57 -080048
49int main(int argc, char** argv) {
mtkleinf5e97822016-01-15 06:19:53 -080050 SkCommandLineFlags::Parse(argc, argv);
51
mtkleind0b82342016-01-15 07:56:20 -080052 const char* path = FLAGS_bytes.isEmpty() ? argv[0] : FLAGS_bytes[0];
bungeman38d909e2016-08-02 14:40:46 -070053 sk_sp<SkData> bytes(SkData::MakeFromFileName(path));
kjlubickdba57342016-01-21 05:03:28 -080054 if (!bytes) {
55 SkDebugf("Could not read %s\n", path);
56 return 2;
57 }
mtklein65e58242016-01-13 12:57:57 -080058
bungeman38d909e2016-08-02 14:40:46 -070059 uint8_t option = calculate_option(bytes.get());
kjlubick2a42f482016-02-16 16:14:23 -080060
mtkleind4387ea2016-01-21 06:13:52 -080061 if (!FLAGS_type.isEmpty()) {
kjlubicke7195772016-10-18 10:06:24 -070062 if (0 == strcmp("api", FLAGS_type[0])) {
63 return fuzz_api(bytes);
64 }
65 if (0 == strcmp("color_deserialize", FLAGS_type[0])) {
66 return fuzz_color_deserialize(bytes);
67 }
68 if (0 == strcmp("icc", FLAGS_type[0])) {
69 return fuzz_icc(bytes);
70 }
71 if (0 == strcmp("image_scale", FLAGS_type[0])) {
72 return fuzz_img(bytes, option, 0);
73 }
74 if (0 == strcmp("image_mode", FLAGS_type[0])) {
75 return fuzz_img(bytes, 0, option);
76 }
77 if (0 == strcmp("skp", FLAGS_type[0])) {
78 return fuzz_skp(bytes);
79 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050080#if SK_SUPPORT_GPU
kjlubicke7195772016-10-18 10:06:24 -070081 if (0 == strcmp("sksl2glsl", FLAGS_type[0])) {
82 return fuzz_sksl2glsl(bytes);
mtkleind4387ea2016-01-21 06:13:52 -080083 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050084#endif
kjlubickdba57342016-01-21 05:03:28 -080085 }
86 return printUsage(argv[0]);
87}
88
kjlubick2a42f482016-02-16 16:14:23 -080089// This adds up the first 1024 bytes and returns it as an 8 bit integer. This allows afl-fuzz to
90// deterministically excercise different paths, or *options* (such as different scaling sizes or
91// different image modes) without needing to introduce a parameter. This way we don't need a
92// image_scale1, image_scale2, image_scale4, etc fuzzer, we can just have a image_scale fuzzer.
93// Clients are expected to transform this number into a different range, e.g. with modulo (%).
94static uint8_t calculate_option(SkData* bytes) {
95 uint8_t total = 0;
96 const uint8_t* data = bytes->bytes();
97 for (size_t i = 0; i < 1024 && i < bytes->size(); i++) {
98 total += data[i];
99 }
100 return total;
101}
102
reed42943c82016-09-12 12:01:44 -0700103int fuzz_api(sk_sp<SkData> bytes) {
mtkleind4387ea2016-01-21 06:13:52 -0800104 const char* name = FLAGS_name.isEmpty() ? "" : FLAGS_name[0];
105
mtklein65e58242016-01-13 12:57:57 -0800106 for (auto r = SkTRegistry<Fuzzable>::Head(); r; r = r->next()) {
107 auto fuzzable = r->factory();
mtkleind4387ea2016-01-21 06:13:52 -0800108 if (0 == strcmp(name, fuzzable.name)) {
mtkleinf5e97822016-01-15 06:19:53 -0800109 SkDebugf("Fuzzing %s...\n", fuzzable.name);
110 Fuzz fuzz(bytes);
mtklein65e58242016-01-13 12:57:57 -0800111 fuzzable.fn(&fuzz);
kjlubick47d158e2016-02-01 08:23:50 -0800112 SkDebugf("[terminated] Success!\n");
kjlubickdba57342016-01-21 05:03:28 -0800113 return 0;
mtklein65e58242016-01-13 12:57:57 -0800114 }
115 }
mtkleind4387ea2016-01-21 06:13:52 -0800116
117 SkDebugf("When using --type api, please choose an API to fuzz with --name/-n:\n");
118 for (auto r = SkTRegistry<Fuzzable>::Head(); r; r = r->next()) {
119 auto fuzzable = r->factory();
120 SkDebugf("\t%s\n", fuzzable.name);
121 }
kjlubickdba57342016-01-21 05:03:28 -0800122 return 1;
123}
124
125static void dump_png(SkBitmap bitmap) {
126 if (!FLAGS_dump.isEmpty()) {
Hal Canarydb683012016-11-23 08:55:18 -0700127 sk_tool_utils::EncodeImageToFile(FLAGS_dump[0], bitmap, SkEncodedImageFormat::kPNG, 100);
kjlubickdba57342016-01-21 05:03:28 -0800128 SkDebugf("Dumped to %s\n", FLAGS_dump[0]);
129 }
130}
131
reed42943c82016-09-12 12:01:44 -0700132int fuzz_img(sk_sp<SkData> bytes, uint8_t scale, uint8_t mode) {
kjlubick2a42f482016-02-16 16:14:23 -0800133 // We can scale 1x, 2x, 4x, 8x, 16x
134 scale = scale % 5;
kjlubick5bd98a22016-02-18 06:27:38 -0800135 float fscale = (float)pow(2.0f, scale);
136 SkDebugf("Scaling factor: %f\n", fscale);
kjlubick2a42f482016-02-16 16:14:23 -0800137
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500138 // We have 5 different modes of decoding.
139 mode = mode % 5;
kjlubick2a42f482016-02-16 16:14:23 -0800140 SkDebugf("Mode: %d\n", mode);
141
142 // This is mostly copied from DMSrcSink's CodecSrc::draw method.
kjlubick47d158e2016-02-01 08:23:50 -0800143 SkDebugf("Decoding\n");
Ben Wagner145dbcd2016-11-03 14:40:50 -0400144 std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(bytes));
kjlubickdba57342016-01-21 05:03:28 -0800145 if (nullptr == codec.get()) {
kjlubick47d158e2016-02-01 08:23:50 -0800146 SkDebugf("[terminated] Couldn't create codec.\n");
kjlubickdba57342016-01-21 05:03:28 -0800147 return 3;
148 }
149
150 SkImageInfo decodeInfo = codec->getInfo();
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500151 if (4 == mode && decodeInfo.colorType() == kIndex_8_SkColorType) {
152 // 4 means animated. Frames beyond the first cannot be decoded to
153 // index 8.
154 decodeInfo = decodeInfo.makeColorType(kN32_SkColorType);
155 }
kjlubick2a42f482016-02-16 16:14:23 -0800156
157 SkISize size = codec->getScaledDimensions(fscale);
158 decodeInfo = decodeInfo.makeWH(size.width(), size.height());
159
kjlubickdba57342016-01-21 05:03:28 -0800160 // Construct a color table for the decode if necessary
Hal Canary2db83612016-11-04 13:02:54 -0400161 sk_sp<SkColorTable> colorTable(nullptr);
kjlubickdba57342016-01-21 05:03:28 -0800162 SkPMColor* colorPtr = nullptr;
163 int* colorCountPtr = nullptr;
164 int maxColors = 256;
165 if (kIndex_8_SkColorType == decodeInfo.colorType()) {
166 SkPMColor colors[256];
167 colorTable.reset(new SkColorTable(colors, maxColors));
168 colorPtr = const_cast<SkPMColor*>(colorTable->readColors());
169 colorCountPtr = &maxColors;
170 }
171
172 SkBitmap bitmap;
173 SkMallocPixelRef::ZeroedPRFactory zeroFactory;
174 SkCodec::Options options;
175 options.fZeroInitialized = SkCodec::kYes_ZeroInitialized;
176
kjlubick2a42f482016-02-16 16:14:23 -0800177 if (!bitmap.tryAllocPixels(decodeInfo, &zeroFactory, colorTable.get())) {
kjlubick47d158e2016-02-01 08:23:50 -0800178 SkDebugf("[terminated] Could not allocate memory. Image might be too large (%d x %d)",
kjlubick2a42f482016-02-16 16:14:23 -0800179 decodeInfo.width(), decodeInfo.height());
kjlubickdba57342016-01-21 05:03:28 -0800180 return 4;
181 }
182
kjlubick2a42f482016-02-16 16:14:23 -0800183 switch (mode) {
184 case 0: {//kCodecZeroInit_Mode, kCodec_Mode
185 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes(), &options,
186 colorPtr, colorCountPtr)) {
187 case SkCodec::kSuccess:
188 SkDebugf("[terminated] Success!\n");
189 break;
190 case SkCodec::kIncompleteInput:
191 SkDebugf("[terminated] Partial Success\n");
192 break;
193 case SkCodec::kInvalidConversion:
194 SkDebugf("Incompatible colortype conversion\n");
195 // Crash to allow afl-fuzz to know this was a bug.
196 raise(SIGSEGV);
197 default:
198 SkDebugf("[terminated] Couldn't getPixels.\n");
199 return 6;
200 }
201 break;
202 }
203 case 1: {//kScanline_Mode
204 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL, colorPtr,
205 colorCountPtr)) {
206 SkDebugf("[terminated] Could not start scanline decoder\n");
207 return 7;
208 }
209
210 void* dst = bitmap.getAddr(0, 0);
211 size_t rowBytes = bitmap.rowBytes();
212 uint32_t height = decodeInfo.height();
213 switch (codec->getScanlineOrder()) {
214 case SkCodec::kTopDown_SkScanlineOrder:
215 case SkCodec::kBottomUp_SkScanlineOrder:
kjlubick2a42f482016-02-16 16:14:23 -0800216 // We do not need to check the return value. On an incomplete
217 // image, memory will be filled with a default value.
218 codec->getScanlines(dst, height, rowBytes);
219 break;
kjlubick2a42f482016-02-16 16:14:23 -0800220 }
kjlubick47d158e2016-02-01 08:23:50 -0800221 SkDebugf("[terminated] Success!\n");
kjlubickdba57342016-01-21 05:03:28 -0800222 break;
kjlubick2a42f482016-02-16 16:14:23 -0800223 }
224 case 2: { //kStripe_Mode
225 const int height = decodeInfo.height();
226 // This value is chosen arbitrarily. We exercise more cases by choosing a value that
227 // does not align with image blocks.
228 const int stripeHeight = 37;
229 const int numStripes = (height + stripeHeight - 1) / stripeHeight;
230
231 // Decode odd stripes
232 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL, colorPtr,
233 colorCountPtr)
234 || SkCodec::kTopDown_SkScanlineOrder != codec->getScanlineOrder()) {
235 // This mode was designed to test the new skip scanlines API in libjpeg-turbo.
236 // Jpegs have kTopDown_SkScanlineOrder, and at this time, it is not interesting
237 // to run this test for image types that do not have this scanline ordering.
238 SkDebugf("[terminated] Could not start top-down scanline decoder\n");
239 return 8;
240 }
241
242 for (int i = 0; i < numStripes; i += 2) {
243 // Skip a stripe
244 const int linesToSkip = SkTMin(stripeHeight, height - i * stripeHeight);
245 codec->skipScanlines(linesToSkip);
246
247 // Read a stripe
248 const int startY = (i + 1) * stripeHeight;
249 const int linesToRead = SkTMin(stripeHeight, height - startY);
250 if (linesToRead > 0) {
251 codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitmap.rowBytes());
252 }
253 }
254
255 // Decode even stripes
256 const SkCodec::Result startResult = codec->startScanlineDecode(decodeInfo, nullptr,
257 colorPtr, colorCountPtr);
258 if (SkCodec::kSuccess != startResult) {
259 SkDebugf("[terminated] Failed to restart scanline decoder with same parameters.\n");
260 return 9;
261 }
262 for (int i = 0; i < numStripes; i += 2) {
263 // Read a stripe
264 const int startY = i * stripeHeight;
265 const int linesToRead = SkTMin(stripeHeight, height - startY);
266 codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitmap.rowBytes());
267
268 // Skip a stripe
269 const int linesToSkip = SkTMin(stripeHeight, height - (i + 1) * stripeHeight);
270 if (linesToSkip > 0) {
271 codec->skipScanlines(linesToSkip);
272 }
273 }
274 SkDebugf("[terminated] Success!\n");
kjlubickdba57342016-01-21 05:03:28 -0800275 break;
kjlubick2a42f482016-02-16 16:14:23 -0800276 }
277 case 3: { //kSubset_Mode
278 // Arbitrarily choose a divisor.
279 int divisor = 2;
280 // Total width/height of the image.
281 const int W = codec->getInfo().width();
282 const int H = codec->getInfo().height();
283 if (divisor > W || divisor > H) {
284 SkDebugf("[terminated] Cannot codec subset: divisor %d is too big "
285 "with dimensions (%d x %d)\n", divisor, W, H);
286 return 10;
287 }
288 // subset dimensions
289 // SkWebpCodec, the only one that supports subsets, requires even top/left boundaries.
290 const int w = SkAlign2(W / divisor);
291 const int h = SkAlign2(H / divisor);
292 SkIRect subset;
293 SkCodec::Options opts;
294 opts.fSubset = &subset;
295 SkBitmap subsetBm;
296 // We will reuse pixel memory from bitmap.
297 void* pixels = bitmap.getPixels();
298 // Keep track of left and top (for drawing subsetBm into canvas). We could use
299 // fscale * x and fscale * y, but we want integers such that the next subset will start
300 // where the last one ended. So we'll add decodeInfo.width() and height().
301 int left = 0;
302 for (int x = 0; x < W; x += w) {
303 int top = 0;
304 for (int y = 0; y < H; y+= h) {
305 // Do not make the subset go off the edge of the image.
306 const int preScaleW = SkTMin(w, W - x);
307 const int preScaleH = SkTMin(h, H - y);
308 subset.setXYWH(x, y, preScaleW, preScaleH);
309 // And fscale
310 // FIXME: Should we have a version of getScaledDimensions that takes a subset
311 // into account?
312 decodeInfo = decodeInfo.makeWH(
313 SkTMax(1, SkScalarRoundToInt(preScaleW * fscale)),
314 SkTMax(1, SkScalarRoundToInt(preScaleH * fscale)));
315 size_t rowBytes = decodeInfo.minRowBytes();
316 if (!subsetBm.installPixels(decodeInfo, pixels, rowBytes, colorTable.get(),
317 nullptr, nullptr)) {
318 SkDebugf("[terminated] Could not install pixels.\n");
319 return 11;
320 }
321 const SkCodec::Result result = codec->getPixels(decodeInfo, pixels, rowBytes,
322 &opts, colorPtr, colorCountPtr);
323 switch (result) {
324 case SkCodec::kSuccess:
325 case SkCodec::kIncompleteInput:
326 SkDebugf("okay\n");
327 break;
328 case SkCodec::kInvalidConversion:
329 if (0 == (x|y)) {
330 // First subset is okay to return unimplemented.
331 SkDebugf("[terminated] Incompatible colortype conversion\n");
332 return 12;
333 }
334 // If the first subset succeeded, a later one should not fail.
335 // fall through to failure
336 case SkCodec::kUnimplemented:
337 if (0 == (x|y)) {
338 // First subset is okay to return unimplemented.
339 SkDebugf("[terminated] subset codec not supported\n");
340 return 13;
341 }
342 // If the first subset succeeded, why would a later one fail?
343 // fall through to failure
344 default:
345 SkDebugf("[terminated] subset codec failed to decode (%d, %d, %d, %d) "
346 "with dimensions (%d x %d)\t error %d\n",
347 x, y, decodeInfo.width(), decodeInfo.height(),
348 W, H, result);
349 return 14;
350 }
351 // translate by the scaled height.
352 top += decodeInfo.height();
353 }
354 // translate by the scaled width.
355 left += decodeInfo.width();
356 }
357 SkDebugf("[terminated] Success!\n");
358 break;
359 }
Leon Scroggins IIIc5a83662016-12-08 09:07:56 -0500360 case 4: { //kAnimated_Mode
361 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
362 if (frameInfos.size() == 0) {
363 SkDebugf("[terminated] Not an animated image\n");
364 break;
365 }
366
367 for (size_t i = 0; i < frameInfos.size(); i++) {
368 options.fFrameIndex = i;
369 auto result = codec->startIncrementalDecode(decodeInfo, bitmap.getPixels(),
370 bitmap.rowBytes(), &options);
371 if (SkCodec::kSuccess != result) {
372 SkDebugf("[terminated] failed to start incremental decode "
373 "in frame %d with error %d\n", i, result);
374 return 15;
375 }
376
377 result = codec->incrementalDecode();
378 if (result == SkCodec::kIncompleteInput) {
379 SkDebugf("okay\n");
380 // Frames beyond this one will not decode.
381 break;
382 }
383 if (result == SkCodec::kSuccess) {
384 SkDebugf("okay - decoded frame %d\n", i);
385 } else {
386 SkDebugf("[terminated] incremental decode failed with "
387 "error %d\n", result);
388 return 16;
389 }
390 }
391 SkDebugf("[terminated] Success!\n");
392 break;
393 }
kjlubickdba57342016-01-21 05:03:28 -0800394 default:
kjlubick2a42f482016-02-16 16:14:23 -0800395 SkDebugf("[terminated] Mode not implemented yet\n");
kjlubickdba57342016-01-21 05:03:28 -0800396 }
397
398 dump_png(bitmap);
mtkleinf5e97822016-01-15 06:19:53 -0800399 return 0;
mtklein65e58242016-01-13 12:57:57 -0800400}
401
reed42943c82016-09-12 12:01:44 -0700402int fuzz_skp(sk_sp<SkData> bytes) {
kjlubickdba57342016-01-21 05:03:28 -0800403 SkMemoryStream stream(bytes);
404 SkDebugf("Decoding\n");
reedca2622b2016-03-18 07:25:55 -0700405 sk_sp<SkPicture> pic(SkPicture::MakeFromStream(&stream));
kjlubickdba57342016-01-21 05:03:28 -0800406 if (!pic) {
kjlubick47d158e2016-02-01 08:23:50 -0800407 SkDebugf("[terminated] Couldn't decode as a picture.\n");
kjlubickdba57342016-01-21 05:03:28 -0800408 return 3;
409 }
410 SkDebugf("Rendering\n");
411 SkBitmap bitmap;
412 if (!FLAGS_dump.isEmpty()) {
413 SkIRect size = pic->cullRect().roundOut();
414 bitmap.allocN32Pixels(size.width(), size.height());
415 }
416 SkCanvas canvas(bitmap);
417 canvas.drawPicture(pic);
kjlubick47d158e2016-02-01 08:23:50 -0800418 SkDebugf("[terminated] Success! Decoded and rendered an SkPicture!\n");
kjlubickdba57342016-01-21 05:03:28 -0800419 dump_png(bitmap);
420 return 0;
421}
mtklein65e58242016-01-13 12:57:57 -0800422
reed42943c82016-09-12 12:01:44 -0700423int fuzz_icc(sk_sp<SkData> bytes) {
Brian Osman526972e2016-10-24 09:24:02 -0400424 sk_sp<SkColorSpace> space(SkColorSpace::MakeICC(bytes->data(), bytes->size()));
kjlubick897a8e32016-06-09 07:15:12 -0700425 if (!space) {
426 SkDebugf("[terminated] Couldn't decode ICC.\n");
427 return 1;
428 }
429 SkDebugf("[terminated] Success! Decoded ICC.\n");
430 return 0;
431}
432
reed42943c82016-09-12 12:01:44 -0700433int fuzz_color_deserialize(sk_sp<SkData> bytes) {
kjlubick3e3c1a52016-06-23 10:49:27 -0700434 sk_sp<SkColorSpace> space(SkColorSpace::Deserialize(bytes->data(), bytes->size()));
435 if (!space) {
436 SkDebugf("[terminated] Couldn't deserialize Colorspace.\n");
437 return 1;
438 }
439 SkDebugf("[terminated] Success! deserialized Colorspace.\n");
440 return 0;
441}
442
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500443#if SK_SUPPORT_GPU
kjlubicke7195772016-10-18 10:06:24 -0700444int fuzz_sksl2glsl(sk_sp<SkData> bytes) {
445 SkSL::Compiler compiler;
Ethan Nicholas9e1138d2016-11-21 10:39:35 -0500446 SkString output;
kjlubicke7195772016-10-18 10:06:24 -0700447 bool result = compiler.toGLSL(SkSL::Program::kFragment_Kind,
Brian Salomonf1dd6772016-11-29 15:27:52 -0500448 SkString((const char*)bytes->data()), *SkSL::ShaderCapsFactory::Default(), &output);
kjlubicke7195772016-10-18 10:06:24 -0700449
450 if (!result) {
451 SkDebugf("[terminated] Couldn't compile input.\n");
452 return 1;
453 }
454 SkDebugf("[terminated] Success! Compiled input.\n");
455 return 0;
456}
Ethan Nicholas7ef4b742016-11-11 15:16:46 -0500457#endif
kjlubicke7195772016-10-18 10:06:24 -0700458
reed42943c82016-09-12 12:01:44 -0700459Fuzz::Fuzz(sk_sp<SkData> bytes) : fBytes(bytes), fNextByte(0) {}
mtklein65e58242016-01-13 12:57:57 -0800460
Kevin Lubick2f535ce2016-11-01 15:01:12 -0400461void Fuzz::signalBug() { SkDebugf("Signal bug\n"); raise(SIGSEGV); }
mtkleina1159422016-01-15 05:46:54 -0800462
kjlubicke5654502016-07-19 16:50:03 -0700463size_t Fuzz::size() { return fBytes->size(); }
464
Kevin Lubick2f535ce2016-11-01 15:01:12 -0400465bool Fuzz::exhausted() {
466 return fBytes->size() == fNextByte;
kjlubick5bd98a22016-02-18 06:27:38 -0800467}