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

Side by Side Diff: fuzz/fuzz.cpp

Issue 1581203003: some fuzz hacking (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: unused 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') | gyp/fuzz.gyp » ('j') | 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 "SkCommandLineFlags.h"
10
11 DEFINE_string2(match, m, "", "The usual match patterns, applied to name.");
12 DEFINE_string2(bytes, b, "", "Path to file containing fuzzed bytes.");
13 9
14 int main(int argc, char** argv) { 10 int main(int argc, char** argv) {
15 SkCommandLineFlags::Parse(argc, argv); 11 ASSERT(argc > 2);
16 SkAutoTUnref<SkData> bytes; 12 const char* name = argv[1];
17 if (!FLAGS_bytes.isEmpty()) { 13 const char* path = argv[2];
18 bytes.reset(SkData::NewFromFileName(FLAGS_bytes[0])); 14
19 } 15 SkAutoTUnref<SkData> bytes(SkData::NewFromFileName(path));
16 Fuzz fuzz(bytes);
20 17
21 for (auto r = SkTRegistry<Fuzzable>::Head(); r; r = r->next()) { 18 for (auto r = SkTRegistry<Fuzzable>::Head(); r; r = r->next()) {
22 auto fuzzable = r->factory(); 19 auto fuzzable = r->factory();
23 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, fuzzable.name)) { 20 if (0 == strcmp(name, fuzzable.name)) {
24 SkDebugf("Running %s...\n", fuzzable.name);
25 Fuzz fuzz(bytes);
26 fuzzable.fn(&fuzz); 21 fuzzable.fn(&fuzz);
22 return 0;
27 } 23 }
28 } 24 }
29 return 0; 25 return 1;
30 } 26 }
31 27
32 28
33 Fuzz::Fuzz(SkData* bytes) : fBytes(SkSafeRef(bytes)) {} 29 Fuzz::Fuzz(SkData* bytes) : fBytes(SkSafeRef(bytes)), fNextByte(0) {}
34 30
35 // These methods are all TODO(kjlubick). 31 template <typename T>
36 uint32_t Fuzz::nextU() { return 0; } 32 static T read(const SkData* data, int* next) {
37 float Fuzz::nextF() { return 0.0f; } 33 ASSERT(sizeof(T) <= data->size());
38 uint32_t Fuzz::nextURange(uint32_t min, uint32_t max) { return min; } 34 if (*next + sizeof(T) > data->size()) {
39 float Fuzz::nextFRange(float min, float max) { return min; } 35 *next = 0;
36 }
37 T val;
38 memcpy(&val, data->bytes() + *next, sizeof(T));
39 *next += sizeof(T);
40 return val;
41 }
40 42
43 uint8_t Fuzz::nextB() { return read<uint8_t >(fBytes, &fNextByte); }
44 uint32_t Fuzz::nextU() { return read<uint32_t>(fBytes, &fNextByte); }
45 float Fuzz::nextF() { return read<float >(fBytes, &fNextByte); }
46
OLDNEW
« no previous file with comments | « fuzz/FuzzPaeth.cpp ('k') | gyp/fuzz.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698