OLD | NEW |
---|---|
(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 #include "core/html/parser/TextResourceDecoder.h" | |
6 | |
7 #include "platform/testing/FuzzedDataProvider.h" | |
8 #include "platform/testing/TestingPlatformSupport.h" | |
9 #include "wtf/text/WTFString.h" | |
10 #include <algorithm> | |
11 | |
12 namespace blink { | |
13 | |
14 class TextResourceDecoderForFuzzing : public TextResourceDecoder { | |
15 public: | |
16 TextResourceDecoderForFuzzing(FuzzedDataProvider& fuzzedData) | |
17 : TextResourceDecoder(String::fromUTF8(fuzzedData.ConsumeBytesInRange(0, 16)), String::fromUTF8(fuzzedData.ConsumeBytesInRange(0, 16)), FuzzedOption(fuz zedData)) | |
esprehn
2016/08/17 20:42:13
why 16?
Charlie Harrison
2016/08/17 21:22:14
Pretty arbitrary. I'll fix this up and add comment
| |
18 { | |
19 } | |
20 | |
21 private: | |
22 static TextResourceDecoder::EncodingDetectionOption FuzzedOption(FuzzedDataP rovider& fuzzedData) | |
23 { | |
24 // Don't use AlwaysUseUTF8ForText which requires knowing the mimeType | |
25 // ahead of time. | |
26 return fuzzedData.ConsumeBool() ? UseAllAutoDetection : UseContentAndBOM BasedDetection; | |
27 } | |
28 }; | |
29 | |
30 int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | |
31 { | |
32 FuzzedDataProvider fuzzedData(data, size); | |
33 TextResourceDecoderForFuzzing decoder(fuzzedData); | |
34 CString bytes = fuzzedData.ConsumeRemainingBytes(); | |
35 decoder.decode(bytes.data(), bytes.length()); | |
36 decoder.flush(); | |
37 return 0; | |
38 } | |
39 | |
40 } // namespace blink | |
41 | |
42 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | |
43 { | |
44 return blink::LLVMFuzzerTestOneInput(data, size); | |
45 } | |
46 | |
47 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) | |
48 { | |
49 // Intentional leak - no need to do cleanup as explained in | |
50 // "Initialization/Cleanup" section of testing/libfuzzer/efficient_fuzzer.md | |
51 DEFINE_STATIC_LOCAL(blink::ScopedUnittestsEnvironmentSetup, testSetup, (*arg c, *argv)); | |
52 ALLOW_UNUSED_LOCAL(testSetup); | |
53 | |
54 return 0; | |
55 } | |
OLD | NEW |