OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // TODO (scroggo): Move this to | 5 // TODO (scroggo): Move this to |
6 // third_party/WebKit/Source/platform/image-decoders ? | 6 // third_party/WebKit/Source/platform/image-decoders ? |
7 | 7 |
8 // Compile with: | 8 // Compile with: |
9 // gn gen out/Fuzz '--args=use_libfuzzer=true is_asan=true | 9 // gn gen out/Fuzz '--args=use_libfuzzer=true is_asan=true |
10 // is_debug=false is_ubsan_security=true' --check | 10 // is_debug=false is_ubsan_security=true' --check |
(...skipping 19 matching lines...) Expand all Loading... |
30 namespace blink { | 30 namespace blink { |
31 | 31 |
32 std::unique_ptr<ImageDecoder> CreateDecoder( | 32 std::unique_ptr<ImageDecoder> CreateDecoder( |
33 ImageDecoder::AlphaOption alpha_option) { | 33 ImageDecoder::AlphaOption alpha_option) { |
34 return WTF::WrapUnique(new PNGImageDecoder( | 34 return WTF::WrapUnique(new PNGImageDecoder( |
35 alpha_option, ColorBehavior::TransformToTargetForTesting(), | 35 alpha_option, ColorBehavior::TransformToTargetForTesting(), |
36 ImageDecoder::kNoDecodedImageByteLimit)); | 36 ImageDecoder::kNoDecodedImageByteLimit)); |
37 } | 37 } |
38 | 38 |
39 int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 39 int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 40 static BlinkFuzzerTestSupport test_support = BlinkFuzzerTestSupport(); |
40 auto buffer = SharedBuffer::Create(data, size); | 41 auto buffer = SharedBuffer::Create(data, size); |
41 // TODO (scroggo): Also test ImageDecoder::AlphaNotPremultiplied? | 42 // TODO (scroggo): Also test ImageDecoder::AlphaNotPremultiplied? |
42 auto decoder = CreateDecoder(ImageDecoder::kAlphaPremultiplied); | 43 auto decoder = CreateDecoder(ImageDecoder::kAlphaPremultiplied); |
43 const bool kAllDataReceived = true; | 44 const bool kAllDataReceived = true; |
44 decoder->SetData(buffer.Get(), kAllDataReceived); | 45 decoder->SetData(buffer.Get(), kAllDataReceived); |
45 decoder->FrameCount(); | 46 decoder->FrameCount(); |
46 if (decoder->Failed()) | 47 if (decoder->Failed()) |
47 return 0; | 48 return 0; |
48 for (size_t frame = 0; frame < decoder->FrameCount(); frame++) { | 49 for (size_t frame = 0; frame < decoder->FrameCount(); frame++) { |
49 decoder->FrameBufferAtIndex(frame); | 50 decoder->FrameBufferAtIndex(frame); |
50 if (decoder->Failed()) | 51 if (decoder->Failed()) |
51 return 0; | 52 return 0; |
52 } | 53 } |
53 return 0; | 54 return 0; |
54 } | 55 } |
55 | 56 |
56 } // namespace blink | 57 } // namespace blink |
57 | 58 |
58 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 59 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
59 return blink::LLVMFuzzerTestOneInput(data, size); | 60 return blink::LLVMFuzzerTestOneInput(data, size); |
60 } | 61 } |
61 | |
62 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { | |
63 blink::InitializeBlinkFuzzTest(argc, argv); | |
64 return 0; | |
65 } | |
OLD | NEW |