| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Fuzz.h" | 8 #include "Fuzz.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
| 11 #include "SkCommandLineFlags.h" | 11 #include "SkCommandLineFlags.h" |
| 12 #include "SkData.h" | 12 #include "SkData.h" |
| 13 #include "SkImage.h" | 13 #include "SkImage.h" |
| 14 #include "SkImageEncoder.h" | 14 #include "SkImageEncoder.h" |
| 15 #include "SkMallocPixelRef.h" | 15 #include "SkMallocPixelRef.h" |
| 16 #include "SkPicture.h" | 16 #include "SkPicture.h" |
| 17 #include "SkPicture.h" |
| 18 #include "SkPicture.h" |
| 17 #include "SkStream.h" | 19 #include "SkStream.h" |
| 18 | 20 |
| 19 #include <cmath> | 21 #include <cmath> |
| 20 #include <signal.h> | 22 #include <signal.h> |
| 21 #include <stdlib.h> | 23 #include <stdlib.h> |
| 22 | 24 |
| 23 DEFINE_string2(bytes, b, "", "A path to a file. This can be the fuzz bytes or a
binary to parse."); | 25 DEFINE_string2(bytes, b, "", "A path to a file. This can be the fuzz bytes or a
binary to parse."); |
| 24 DEFINE_string2(name, n, "", "If --type is 'api', fuzz the API with this name."); | 26 DEFINE_string2(name, n, "", "If --type is 'api', fuzz the API with this name."); |
| 25 | 27 |
| 26 DEFINE_string2(type, t, "api", "How to interpret --bytes, either 'image_scale',
'image_mode', 'skp', 'icc', or 'api'."); | 28 DEFINE_string2(type, t, "api", "How to interpret --bytes, either 'image_scale',
'image_mode', 'skp', 'icc', or 'api'."); |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } | 399 } |
| 398 SkDebugf("[terminated] Success! deserialized Colorspace.\n"); | 400 SkDebugf("[terminated] Success! deserialized Colorspace.\n"); |
| 399 return 0; | 401 return 0; |
| 400 } | 402 } |
| 401 | 403 |
| 402 Fuzz::Fuzz(SkData* bytes) : fBytes(SkSafeRef(bytes)), fNextByte(0) {} | 404 Fuzz::Fuzz(SkData* bytes) : fBytes(SkSafeRef(bytes)), fNextByte(0) {} |
| 403 | 405 |
| 404 void Fuzz::signalBug () { SkDebugf("Signal bug\n"); raise(SIGSEGV); } | 406 void Fuzz::signalBug () { SkDebugf("Signal bug\n"); raise(SIGSEGV); } |
| 405 void Fuzz::signalBoring() { SkDebugf("Signal boring\n"); exit(0); } | 407 void Fuzz::signalBoring() { SkDebugf("Signal boring\n"); exit(0); } |
| 406 | 408 |
| 409 size_t Fuzz::size() { return fBytes->size(); } |
| 410 |
| 411 size_t Fuzz::remaining() { |
| 412 return fBytes->size() - fNextByte; |
| 413 } |
| 414 |
| 407 template <typename T> | 415 template <typename T> |
| 408 T Fuzz::nextT() { | 416 T Fuzz::nextT() { |
| 409 if (fNextByte + sizeof(T) > fBytes->size()) { | 417 if (fNextByte + sizeof(T) > fBytes->size()) { |
| 410 this->signalBoring(); | 418 this->signalBoring(); |
| 411 } | 419 } |
| 412 | 420 |
| 413 T val; | 421 T val; |
| 414 memcpy(&val, fBytes->bytes() + fNextByte, sizeof(T)); | 422 memcpy(&val, fBytes->bytes() + fNextByte, sizeof(T)); |
| 415 fNextByte += sizeof(T); | 423 fNextByte += sizeof(T); |
| 416 return val; | 424 return val; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 444 if (min > max) { | 452 if (min > max) { |
| 445 SkDebugf("Check mins and maxes (%f, %f)\n", min, max); | 453 SkDebugf("Check mins and maxes (%f, %f)\n", min, max); |
| 446 this->signalBoring(); | 454 this->signalBoring(); |
| 447 } | 455 } |
| 448 float f = std::abs(this->nextF()); | 456 float f = std::abs(this->nextF()); |
| 449 if (!std::isnormal(f) && f != 0.0) { | 457 if (!std::isnormal(f) && f != 0.0) { |
| 450 this->signalBoring(); | 458 this->signalBoring(); |
| 451 } | 459 } |
| 452 return min + fmod(f, (max - min + 1)); | 460 return min + fmod(f, (max - min + 1)); |
| 453 } | 461 } |
| OLD | NEW |