Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: fuzz/fuzz.cpp

Issue 1585353002: fuzz: signalBug() / signalBoring() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: stdlib for abs() Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fuzz/FuzzPaeth.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdlib.h>
10 #include <signal.h>
9 11
10 int main(int argc, char** argv) { 12 int main(int argc, char** argv) {
11 ASSERT(argc > 2); 13 if (argc < 3) {
14 SkDebugf("Usage: %s <fuzz name> <path/to/fuzzed.data>\n", argv[0]);
15 return 1;
16 }
12 const char* name = argv[1]; 17 const char* name = argv[1];
13 const char* path = argv[2]; 18 const char* path = argv[2];
14 19
15 SkAutoTUnref<SkData> bytes(SkData::NewFromFileName(path)); 20 SkAutoTUnref<SkData> bytes(SkData::NewFromFileName(path));
16 Fuzz fuzz(bytes); 21 Fuzz fuzz(bytes);
17 22
18 for (auto r = SkTRegistry<Fuzzable>::Head(); r; r = r->next()) { 23 for (auto r = SkTRegistry<Fuzzable>::Head(); r; r = r->next()) {
19 auto fuzzable = r->factory(); 24 auto fuzzable = r->factory();
20 if (0 == strcmp(name, fuzzable.name)) { 25 if (0 == strcmp(name, fuzzable.name)) {
26 SkDebugf("Running %s\n", fuzzable.name);
21 fuzzable.fn(&fuzz); 27 fuzzable.fn(&fuzz);
22 return 0; 28 return 0;
23 } 29 }
24 } 30 }
25 return 1; 31 return 1;
26 } 32 }
27 33
28 34
29 Fuzz::Fuzz(SkData* bytes) : fBytes(SkSafeRef(bytes)), fNextByte(0) {} 35 Fuzz::Fuzz(SkData* bytes) : fBytes(SkSafeRef(bytes)), fNextByte(0) {}
30 36
37 void Fuzz::signalBug () { raise(SIGSEGV); }
38 void Fuzz::signalBoring() { exit(0); }
39
31 template <typename T> 40 template <typename T>
32 static T read(const SkData* data, int* next) { 41 T Fuzz::nextT() {
33 ASSERT(sizeof(T) <= data->size()); 42 if (fNextByte + sizeof(T) > fBytes->size()) {
34 if (*next + sizeof(T) > data->size()) { 43 this->signalBoring();
35 *next = 0;
36 } 44 }
45
37 T val; 46 T val;
38 memcpy(&val, data->bytes() + *next, sizeof(T)); 47 memcpy(&val, fBytes->bytes() + fNextByte, sizeof(T));
39 *next += sizeof(T); 48 fNextByte += sizeof(T);
40 return val; 49 return val;
41 } 50 }
42 51
43 uint8_t Fuzz::nextB() { return read<uint8_t >(fBytes, &fNextByte); } 52 uint8_t Fuzz::nextB() { return this->nextT<uint8_t >(); }
44 uint32_t Fuzz::nextU() { return read<uint32_t>(fBytes, &fNextByte); } 53 uint32_t Fuzz::nextU() { return this->nextT<uint32_t>(); }
45 float Fuzz::nextF() { return read<float >(fBytes, &fNextByte); } 54 float Fuzz::nextF() { return this->nextT<float >(); }
46 55
OLDNEW
« no previous file with comments | « fuzz/FuzzPaeth.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698