OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "platform/wtf/text/TextCodec.h" | 5 #include "platform/wtf/text/TextCodec.h" |
6 | 6 |
7 #include "platform/testing/BlinkFuzzerTestSupport.h" | 7 #include "platform/testing/BlinkFuzzerTestSupport.h" |
8 #include "platform/testing/FuzzedDataProvider.h" | 8 #include "platform/testing/FuzzedDataProvider.h" |
9 #include "platform/wtf/text/CString.h" | 9 #include "platform/wtf/text/CString.h" |
10 #include "platform/wtf/text/TextEncoding.h" | 10 #include "platform/wtf/text/TextEncoding.h" |
11 #include "platform/wtf/text/TextEncodingRegistry.h" | 11 #include "platform/wtf/text/TextEncodingRegistry.h" |
12 | 12 |
13 using namespace blink; | 13 using namespace blink; |
14 | 14 |
15 // TODO(jsbell): This fuzzes code in wtf/ but has dependencies on platform/, | 15 // TODO(jsbell): This fuzzes code in wtf/ but has dependencies on platform/, |
16 // so it must live in the latter directory. Once wtf/ moves into platform/wtf | 16 // so it must live in the latter directory. Once wtf/ moves into platform/wtf |
17 // this should move there as well. | 17 // this should move there as well. |
18 | 18 |
19 WTF::FlushBehavior kFlushBehavior[] = {WTF::kDoNotFlush, WTF::kFetchEOF, | 19 WTF::FlushBehavior kFlushBehavior[] = {WTF::kDoNotFlush, WTF::kFetchEOF, |
20 WTF::kDataEOF}; | 20 WTF::kDataEOF}; |
21 | 21 |
22 WTF::UnencodableHandling kUnencodableHandlingOptions[] = { | 22 WTF::UnencodableHandling kUnencodableHandlingOptions[] = { |
23 WTF::kQuestionMarksForUnencodables, WTF::kEntitiesForUnencodables, | 23 WTF::kQuestionMarksForUnencodables, WTF::kEntitiesForUnencodables, |
24 WTF::kURLEncodedEntitiesForUnencodables, | 24 WTF::kURLEncodedEntitiesForUnencodables, |
25 WTF::kCSSEncodedEntitiesForUnencodables}; | 25 WTF::kCSSEncodedEntitiesForUnencodables}; |
26 | 26 |
27 class TextCodecFuzzHarness {}; | 27 class TextCodecFuzzHarness {}; |
28 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { | |
29 InitializeBlinkFuzzTest(argc, argv); | |
30 return 0; | |
31 } | |
32 | 28 |
33 // Fuzzer for WTF::TextCodec. | 29 // Fuzzer for WTF::TextCodec. |
34 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 30 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 31 static BlinkFuzzerTestSupport test_support = BlinkFuzzerTestSupport(); |
35 // The fuzzer picks 3 bytes off the end of the data to initialize metadata, so | 32 // The fuzzer picks 3 bytes off the end of the data to initialize metadata, so |
36 // abort if the input is smaller than that. | 33 // abort if the input is smaller than that. |
37 if (size < 3) | 34 if (size < 3) |
38 return 0; | 35 return 0; |
39 | 36 |
40 // TODO(csharrison): When crbug.com/701825 is resolved, add the rest of the | 37 // TODO(csharrison): When crbug.com/701825 is resolved, add the rest of the |
41 // text codecs. | 38 // text codecs. |
42 | 39 |
43 // Initializes the codec map. | 40 // Initializes the codec map. |
44 static const WTF::TextEncoding encoding = WTF::TextEncoding( | 41 static const WTF::TextEncoding encoding = WTF::TextEncoding( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 83 |
87 // Round trip the bytes (aka encode the decoded bytes). | 84 // Round trip the bytes (aka encode the decoded bytes). |
88 if (decoded.Is8Bit()) { | 85 if (decoded.Is8Bit()) { |
89 codec->Encode(decoded.Characters8(), decoded.length(), unencodableHandling); | 86 codec->Encode(decoded.Characters8(), decoded.length(), unencodableHandling); |
90 } else { | 87 } else { |
91 codec->Encode(decoded.Characters16(), decoded.length(), | 88 codec->Encode(decoded.Characters16(), decoded.length(), |
92 unencodableHandling); | 89 unencodableHandling); |
93 } | 90 } |
94 return 0; | 91 return 0; |
95 } | 92 } |
OLD | NEW |