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

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

Issue 2261873002: Add fuzzer for HTMLPreloadScanner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/HTMLPreloadScannerFuzzer.cpp
diff --git a/third_party/WebKit/Source/core/html/parser/TextResourceDecoderFuzzer.cpp b/third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerFuzzer.cpp
similarity index 52%
copy from third_party/WebKit/Source/core/html/parser/TextResourceDecoderFuzzer.cpp
copy to third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerFuzzer.cpp
index e19011319fa1df5c8461662d7fcb9db30b769cce..d487e1bd80853679a2f70f27a2723ff0d031c9e4 100644
--- a/third_party/WebKit/Source/core/html/parser/TextResourceDecoderFuzzer.cpp
+++ b/third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerFuzzer.cpp
@@ -2,10 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "core/MediaTypeNames.h"
+#include "core/css/MediaValuesCached.h"
+#include "core/frame/Settings.h"
+#include "core/html/HTMLDocument.h"
+#include "core/html/parser/HTMLDocumentParser.h"
#include "core/html/parser/TextResourceDecoder.h"
-
+#include "core/loader/TextResourceDecoderBuilder.h"
+#include "core/testing/DummyPageHolder.h"
#include "platform/testing/FuzzedDataProvider.h"
#include "platform/testing/TestingPlatformSupport.h"
+#include "wtf/PtrUtil.h"
#include "wtf/text/WTFString.h"
#include <algorithm>
@@ -35,13 +42,57 @@ private:
}
};
+struct CachedDocumentParametersForFuzzing : public CachedDocumentParameters {
+ CachedDocumentParametersForFuzzing(FuzzedDataProvider& fuzzedData)
+ {
kouhei (in TOK) 2016/08/22 05:48:28 maybe simply unique_ptr<CachedDocumentParameters>
+ doHtmlPreloadScanning = fuzzedData.ConsumeBool();
+ doDocumentWritePreloadScanning = fuzzedData.ConsumeBool();
+ }
+};
+
+class MockResourcePreloader : public ResourcePreloader {
+ void preload(std::unique_ptr<PreloadRequest>, const NetworkHintsInterface&) override
+ {
+ }
+};
+
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
FuzzedDataProvider fuzzedData(data, size);
+
+ HTMLParserOptions options;
+ options.scriptEnabled = fuzzedData.ConsumeBool();
+ options.pluginsEnabled = fuzzedData.ConsumeBool();
+
+ CachedDocumentParametersForFuzzing* documentParameters = new CachedDocumentParametersForFuzzing(fuzzedData);
+
+ KURL documentURL(ParsedURLString, "http://whatever.test/");
+
+ // Copied from HTMLPreloadScannerTest. May be worthwhile to fuzz.
+ MediaValuesCached::MediaValuesCachedData mediaData;
+ mediaData.viewportWidth = 500;
+ mediaData.viewportHeight = 600;
+ mediaData.deviceWidth = 700;
+ mediaData.deviceHeight = 800;
+ mediaData.devicePixelRatio = 2.0;
+ mediaData.colorBitsPerComponent = 24;
+ mediaData.monochromeBitsPerComponent = 0;
+ mediaData.primaryPointerType = PointerTypeFine;
+ mediaData.defaultFontSize = 16;
+ mediaData.threeDEnabled = true;
+ mediaData.mediaType = MediaTypeNames::screen;
+ mediaData.strictMode = true;
+ mediaData.displayMode = WebDisplayModeBrowser;
+
+ MockResourcePreloader preloader;
+
+ std::unique_ptr<HTMLPreloadScanner> scanner = HTMLPreloadScanner::create(options, documentURL, wrapUnique(documentParameters), mediaData);
+
TextResourceDecoderForFuzzing decoder(fuzzedData);
CString bytes = fuzzedData.ConsumeRemainingBytes();
- decoder.decode(bytes.data(), bytes.length());
- decoder.flush();
+ String decodedBytes = decoder.decode(bytes.data(), bytes.length());
+ scanner->appendToEnd(decodedBytes);
+ scanner->scanAndPreload(&preloader, KURL(), nullptr);
return 0;
}

Powered by Google App Engine
This is Rietveld 408576698