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

Unified Diff: third_party/WebKit/Source/core/html/parser/TextResourceDecoderFuzzer.cpp

Issue 2250263003: Move FuzzedDataProvider to //base and expose to blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ... also remove PLATFORM_EXPORT Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/parser/TextResourceDecoderFuzzer.cpp
diff --git a/third_party/WebKit/Source/core/html/parser/TextResourceDecoderFuzzer.cpp b/third_party/WebKit/Source/core/html/parser/TextResourceDecoderFuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e19011319fa1df5c8461662d7fcb9db30b769cce
--- /dev/null
+++ b/third_party/WebKit/Source/core/html/parser/TextResourceDecoderFuzzer.cpp
@@ -0,0 +1,63 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/html/parser/TextResourceDecoder.h"
+
+#include "platform/testing/FuzzedDataProvider.h"
+#include "platform/testing/TestingPlatformSupport.h"
+#include "wtf/text/WTFString.h"
+#include <algorithm>
+
+namespace blink {
+
+class TextResourceDecoderForFuzzing : public TextResourceDecoder {
+public:
+ // Note: mimeTypes can be quite long and still valid for XML. See the
+ // comment in DOMImplementation.cpp which says:
+ // Per RFCs 3023 and 2045, an XML MIME type is of the form:
+ // ^[0-9a-zA-Z_\\-+~!$\\^{}|.%'`#&*]+/[0-9a-zA-Z_\\-+~!$\\^{}|.%'`#&*]+\+xml$
+ //
+ // Similarly, charsets can be long too (see the various encodings in
+ // wtf/text). For instance: "unicode-1-1-utf-8". To ensure good coverage,
+ // set a generous max limit for these sizes (32 bytes should be good).
+ TextResourceDecoderForFuzzing(FuzzedDataProvider& fuzzedData)
+ : TextResourceDecoder(String::fromUTF8(fuzzedData.ConsumeBytesInRange(0, 32)), String::fromUTF8(fuzzedData.ConsumeBytesInRange(0, 32)), FuzzedOption(fuzzedData))
+ {
+ }
+
+private:
+ static TextResourceDecoder::EncodingDetectionOption FuzzedOption(FuzzedDataProvider& fuzzedData)
+ {
+ // Don't use AlwaysUseUTF8ForText which requires knowing the mimeType
+ // ahead of time.
+ return fuzzedData.ConsumeBool() ? UseAllAutoDetection : UseContentAndBOMBasedDetection;
+ }
+};
+
+int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ FuzzedDataProvider fuzzedData(data, size);
+ TextResourceDecoderForFuzzing decoder(fuzzedData);
+ CString bytes = fuzzedData.ConsumeRemainingBytes();
+ decoder.decode(bytes.data(), bytes.length());
+ decoder.flush();
+ return 0;
+}
+
+} // namespace blink
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ return blink::LLVMFuzzerTestOneInput(data, size);
+}
+
+extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
+{
+ // Intentional leak - no need to do cleanup as explained in
+ // "Initialization/Cleanup" section of testing/libfuzzer/efficient_fuzzer.md
+ DEFINE_STATIC_LOCAL(blink::ScopedUnittestsEnvironmentSetup, testSetup, (*argc, *argv));
+ ALLOW_UNUSED_LOCAL(testSetup);
+
+ return 0;
+}
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/TextResourceDecoder.h ('k') | third_party/WebKit/Source/platform/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698