Chromium Code Reviews| 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 "wtf/text/TextCodec.h" | |
| 6 | |
| 7 #include "platform/testing/BlinkFuzzerTestSupport.h" | |
| 8 #include "wtf/Vector.h" | |
| 9 #include "wtf/text/CString.h" | |
| 10 #include "wtf/text/TextEncoding.h" | |
| 11 #include "wtf/text/TextEncodingRegistry.h" | |
| 12 #include "wtf/text/WTFString.h" | |
| 13 | |
| 14 using namespace blink; | |
| 15 | |
| 16 // TODO(jsbell): This fuzzes code in wtf/ but has dependencies on platform/, | |
| 17 // so it must live in the latter directory. Once wtf/ moves into platform/wtf | |
| 18 // this should move there as well. | |
| 19 | |
| 20 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { | |
| 21 InitializeBlinkFuzzTest(argc, argv); | |
| 22 return 0; | |
| 23 } | |
| 24 | |
| 25 // Fuzzer for WTF::TextCodec. | |
| 26 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | |
| 27 Vector<String> encodings = WTF::getEncodingNamesForTesting(); | |
|
Charlie Harrison
2016/12/07 16:07:15
Can you make all these Vectors static? It is ineff
| |
| 28 | |
| 29 Vector<WTF::FlushBehavior> flushOptions; | |
| 30 flushOptions.append(WTF::DoNotFlush); | |
| 31 flushOptions.append(WTF::FetchEOF); | |
| 32 flushOptions.append(WTF::DataEOF); | |
| 33 | |
| 34 Vector<bool> stopOnErrorOptions; | |
| 35 stopOnErrorOptions.append(false); | |
| 36 stopOnErrorOptions.append(true); | |
| 37 | |
| 38 Vector<WTF::UnencodableHandling> unencodableHandlingOptions; | |
| 39 unencodableHandlingOptions.append(WTF::QuestionMarksForUnencodables); | |
| 40 unencodableHandlingOptions.append(WTF::EntitiesForUnencodables); | |
| 41 unencodableHandlingOptions.append(WTF::URLEncodedEntitiesForUnencodables); | |
| 42 unencodableHandlingOptions.append(WTF::CSSEncodedEntitiesForUnencodables); | |
| 43 | |
| 44 for (const auto& encodingName : encodings) { | |
| 45 WTF::TextEncoding encoding(encodingName); | |
|
Charlie Harrison
2016/12/07 16:07:15
Maybe have a Vector of TextEncodings instead of na
| |
| 46 | |
| 47 for (const auto& flush : flushOptions) { | |
| 48 for (const auto& stopOnError : stopOnErrorOptions) { | |
| 49 std::unique_ptr<TextCodec> codec = newTextCodec(encoding); | |
|
Charlie Harrison
2016/12/07 16:07:15
It would be good to avoid all the allocations of T
| |
| 50 bool sawError; | |
| 51 codec->decode(reinterpret_cast<const char*>(data), size, flush, | |
| 52 stopOnError, sawError); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 for (const auto& unencodableHandling : unencodableHandlingOptions) { | |
| 57 if (size % sizeof(LChar) == 0) { | |
| 58 std::unique_ptr<TextCodec> codec = newTextCodec(encoding); | |
| 59 codec->encode(reinterpret_cast<const LChar*>(data), | |
| 60 size / sizeof(LChar), unencodableHandling); | |
| 61 } | |
| 62 if (size % sizeof(UChar) == 0) { | |
| 63 std::unique_ptr<TextCodec> codec = newTextCodec(encoding); | |
| 64 codec->encode(reinterpret_cast<const UChar*>(data), | |
| 65 size / sizeof(UChar), unencodableHandling); | |
| 66 } | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 return 0; | |
| 71 } | |
| OLD | NEW |