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

Side by Side Diff: third_party/WebKit/Source/platform/PngFuzzer.cpp

Issue 2603303003: Add fuzzer for (A)PNG decoder (Closed)
Patch Set: Fix typo Created 3 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 | « third_party/WebKit/Source/platform/BUILD.gn ('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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // TODO (scroggo): Move this to
6 // third_party/WebKit/Source/platform/image-decoders ?
7
8 // Compile with:
9 // gn gen out/Fuzz '--args=use_libfuzzer=true is_asan=true
10 // is_debug=false is_ubsan_security=true' --check
11 // ninja -C out/Fuzz blink_png_decoder_fuzzer
12 //
13 // Run with:
14 // ./out/Fuzz/blink_png_decoder_fuzzer
15 // third_party/WebKit/LayoutTests/images/resources/pngfuzz
16 //
17 // Alternatively, it can be run with:
18 // ./out/Fuzz/blink_png_decoder_fuzzer ~/another_dir_to_store_corpus
19 // third_party/WebKit/LayoutTests/images/resources/pngfuzz
20 //
21 // so the fuzzer will read both directories passed, but all new generated
22 // testcases will go into ~/another_dir_to_store_corpus
23 //
24 // For more details, see
25 // https://chromium.googlesource.com/chromium/src/+/master/testing/libfuzzer/REA DME.md
26
27 #include "platform/image-decoders/png/PNGImageDecoder.cpp"
28 #include "platform/testing/BlinkFuzzerTestSupport.h"
29
30 namespace blink {
31
32 std::unique_ptr<ImageDecoder> createDecoder(
33 ImageDecoder::AlphaOption alphaOption) {
34 return WTF::wrapUnique(new PNGImageDecoder(
35 alphaOption, ColorBehavior::transformToTargetForTesting(),
36 ImageDecoder::noDecodedImageByteLimit));
37 }
38
39 int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
40 auto buffer = SharedBuffer::create(data, size);
41 // TODO (scroggo): Also test ImageDecoder::AlphaNotPremultiplied?
42 auto decoder = createDecoder(ImageDecoder::AlphaPremultiplied);
43 const bool allDataReceived = true;
44 decoder->setData(buffer.get(), allDataReceived);
45 decoder->frameCount();
46 if (decoder->failed())
47 return 0;
48 for (size_t frame = 0; frame < decoder->frameCount(); frame++) {
49 decoder->frameBufferAtIndex(frame);
50 if (decoder->failed())
51 return 0;
52 }
53 return 0;
54 }
55
56 } // namespace blink
57
58 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
59 return blink::LLVMFuzzerTestOneInput(data, size);
60 }
61
62 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
63 blink::InitializeBlinkFuzzTest(argc, argv);
64 return 0;
65 }
OLDNEW
« no previous file with comments | « 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