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

Unified Diff: third_party/WebKit/Source/platform/PngFuzzer.cpp

Issue 2578263002: Add fuzzer for (A)PNG decoder (Closed)
Patch Set: Target fuzz towards static PNG and animated PNG Created 4 years 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
Index: third_party/WebKit/Source/platform/PngFuzzer.cpp
diff --git a/third_party/WebKit/Source/platform/PngFuzzer.cpp b/third_party/WebKit/Source/platform/PngFuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..4cad4f6155757edaafb08db5c0eaa7d75b02ef82
--- /dev/null
+++ b/third_party/WebKit/Source/platform/PngFuzzer.cpp
@@ -0,0 +1,62 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
Noel Gordon 2017/01/03 04:12:39 location: third_party/WebKit/Source/platform/PngFu
scroggo_chromium 2017/01/03 18:24:15 I do not have a strong preference. Added the TODO.
Noel Gordon 2017/01/03 23:57:16 My thinking was if more fuzzers are coming / are b
+// Compile with:
+// gn gen out/Fuzz '--args=use_libfuzzer=true is_asan=true
+// is_debug=false is_ubsan_security=true' --check
+// ninja -C out/Fuzz png_fuzzer
+//
+// Run with:
+// ./out/Fuzz/png_fuzzer third_party/WebKit/LayoutTests/images/resources/pngfuzz
mmoroz 2017/01/03 08:18:36 This command will write new files into `third_part
scroggo_chromium 2017/01/03 18:24:15 Added a comment regarding this.
+//
+// For more details, see
+// https://chromium.googlesource.com/chromium/src/+/master/testing/libfuzzer/README.md
+
+#include "platform/image-decoders/png/PNGImageDecoder.cpp"
+#include "platform/testing/BlinkFuzzerTestSupport.h"
+#include "public/platform/WebIconSizesParser.h"
+#include "public/platform/WebSize.h"
+#include "public/platform/WebString.h"
Noel Gordon 2017/01/03 04:12:39 nit: do you need the following includes? +#includ
scroggo_chromium 2017/01/03 18:24:15 No. Removed.
+
+namespace blink {
+
+std::unique_ptr<ImageDecoder> createDecoder(
+ ImageDecoder::AlphaOption alphaOption) {
+ return WTF::wrapUnique(new PNGImageDecoder(
+ alphaOption, ColorBehavior::transformToTargetForTesting(),
Noel Gordon 2017/01/03 04:12:39 /me curious: do any of your seed images have a col
scroggo_chromium 2017/01/03 18:24:15 oval.png is sRGB. The rest do not.
+ ImageDecoder::noDecodedImageByteLimit));
+}
+
+std::unique_ptr<ImageDecoder> createDecoder() {
+ return createDecoder(ImageDecoder::AlphaNotPremultiplied);
Noel Gordon 2017/01/03 04:12:39 The default code path used by Blink would be _Imag
scroggo_chromium 2017/01/03 18:24:15 Good point. Will default to ImageDecoder::AlphaPre
+}
+
+// This function will be called by ClusterFuzz. If this does not crash, the
+// test passes. It parses the frame count and then tries to decode each frame
+// in the image.
Noel Gordon 2017/01/03 04:12:39 Not sure about the value of this comment. "It par
mmoroz 2017/01/03 08:18:36 Technically, this function will be called by libFu
scroggo_chromium 2017/01/03 18:24:15 Removed the comment.
+int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ auto buffer = SharedBuffer::create(data, size);
+ auto decoder = createDecoder();
+ decoder->setData(buffer.get(), true);
Noel Gordon 2017/01/03 04:12:39 optional: up to you, but I usually write this as
scroggo_chromium 2017/01/03 18:24:15 Done.
+ decoder->frameCount();
+ if (decoder->failed())
+ return 0;
+ for (size_t frame = 0; frame < decoder->frameCount(); frame++) {
+ decoder->frameBufferAtIndex(frame);
+ if (decoder->failed())
+ return 0;
+ }
+ return 0;
+}
+
+} // namespace blink
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ return blink::LLVMFuzzerTestOneInput(data, size);
+}
+
+extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
+ blink::InitializeBlinkFuzzTest(argc, argv);
+ return 0;
+}
« third_party/WebKit/Source/platform/BUILD.gn ('K') | « third_party/WebKit/Source/platform/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698