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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fuzz/FuzzPaeth.cpp ('k') | gyp/fuzz.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fuzz/fuzz.cpp
diff --git a/fuzz/fuzz.cpp b/fuzz/fuzz.cpp
index 6e3179095103916661273bef6fadd4e5c7d6f51c..929ba7a4cf54dd4d7243d968cb7bfc9182ad7c1c 100644
--- a/fuzz/fuzz.cpp
+++ b/fuzz/fuzz.cpp
@@ -6,35 +6,41 @@
*/
#include "Fuzz.h"
-#include "SkCommandLineFlags.h"
-
-DEFINE_string2(match, m, "", "The usual match patterns, applied to name.");
-DEFINE_string2(bytes, b, "", "Path to file containing fuzzed bytes.");
int main(int argc, char** argv) {
- SkCommandLineFlags::Parse(argc, argv);
- SkAutoTUnref<SkData> bytes;
- if (!FLAGS_bytes.isEmpty()) {
- bytes.reset(SkData::NewFromFileName(FLAGS_bytes[0]));
- }
+ ASSERT(argc > 2);
+ const char* name = argv[1];
+ const char* path = argv[2];
+
+ SkAutoTUnref<SkData> bytes(SkData::NewFromFileName(path));
+ Fuzz fuzz(bytes);
for (auto r = SkTRegistry<Fuzzable>::Head(); r; r = r->next()) {
auto fuzzable = r->factory();
- if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, fuzzable.name)) {
- SkDebugf("Running %s...\n", fuzzable.name);
- Fuzz fuzz(bytes);
+ if (0 == strcmp(name, fuzzable.name)) {
fuzzable.fn(&fuzz);
+ return 0;
}
}
- return 0;
+ return 1;
}
-Fuzz::Fuzz(SkData* bytes) : fBytes(SkSafeRef(bytes)) {}
+Fuzz::Fuzz(SkData* bytes) : fBytes(SkSafeRef(bytes)), fNextByte(0) {}
+
+template <typename T>
+static T read(const SkData* data, int* next) {
+ ASSERT(sizeof(T) <= data->size());
+ if (*next + sizeof(T) > data->size()) {
+ *next = 0;
+ }
+ T val;
+ memcpy(&val, data->bytes() + *next, sizeof(T));
+ *next += sizeof(T);
+ return val;
+}
-// These methods are all TODO(kjlubick).
-uint32_t Fuzz::nextU() { return 0; }
-float Fuzz::nextF() { return 0.0f; }
-uint32_t Fuzz::nextURange(uint32_t min, uint32_t max) { return min; }
-float Fuzz::nextFRange(float min, float max) { return min; }
+uint8_t Fuzz::nextB() { return read<uint8_t >(fBytes, &fNextByte); }
+uint32_t Fuzz::nextU() { return read<uint32_t>(fBytes, &fNextByte); }
+float Fuzz::nextF() { return read<float >(fBytes, &fNextByte); }
« 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