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

Side by Side 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: rebase 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 unified diff | Download patch
OLDNEW
(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/MediaTypeNames.h"
6 #include "core/css/MediaValuesCached.h"
7 #include "core/html/HTMLDocument.h"
8 #include "core/html/parser/HTMLDocumentParser.h"
9 #include "core/html/parser/TextResourceDecoderForFuzzing.h"
10 #include "platform/testing/BlinkFuzzerTestSupport.h"
11 #include "platform/testing/FuzzedDataProvider.h"
12
13 namespace blink {
14
15 std::unique_ptr<CachedDocumentParameters> cachedDocumentParametersForFuzzing(Fuz zedDataProvider& fuzzedData)
16 {
17 std::unique_ptr<CachedDocumentParameters> documentParameters = CachedDocumen tParameters::create();
18 documentParameters->doHtmlPreloadScanning = fuzzedData.ConsumeBool();
19 documentParameters->doDocumentWritePreloadScanning = fuzzedData.ConsumeBool( );
20 // TODO(csharrison): How should this be fuzzed?
21 documentParameters->defaultViewportMinWidth = Length();
22 documentParameters->viewportMetaZeroValuesQuirk = fuzzedData.ConsumeBool();
23 documentParameters->viewportMetaEnabled = fuzzedData.ConsumeBool();
24 return documentParameters;
25 }
26
27 class MockResourcePreloader : public ResourcePreloader {
28 void preload(std::unique_ptr<PreloadRequest>, const NetworkHintsInterface&) override
29 {
30 }
31 };
32
33 int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
34 {
35 FuzzedDataProvider fuzzedData(data, size);
36
37 HTMLParserOptions options;
38 options.scriptEnabled = fuzzedData.ConsumeBool();
39 options.pluginsEnabled = fuzzedData.ConsumeBool();
40
41 std::unique_ptr<CachedDocumentParameters> documentParameters = cachedDocumen tParametersForFuzzing(fuzzedData);
42
43 KURL documentURL(ParsedURLString, "http://whatever.test/");
44
45 // Copied from HTMLPreloadScannerTest. May be worthwhile to fuzz.
46 MediaValuesCached::MediaValuesCachedData mediaData;
47 mediaData.viewportWidth = 500;
48 mediaData.viewportHeight = 600;
49 mediaData.deviceWidth = 700;
50 mediaData.deviceHeight = 800;
51 mediaData.devicePixelRatio = 2.0;
52 mediaData.colorBitsPerComponent = 24;
53 mediaData.monochromeBitsPerComponent = 0;
54 mediaData.primaryPointerType = PointerTypeFine;
55 mediaData.defaultFontSize = 16;
56 mediaData.threeDEnabled = true;
57 mediaData.mediaType = MediaTypeNames::screen;
58 mediaData.strictMode = true;
59 mediaData.displayMode = WebDisplayModeBrowser;
60
61 MockResourcePreloader preloader;
62
63 std::unique_ptr<HTMLPreloadScanner> scanner = HTMLPreloadScanner::create(opt ions, documentURL, std::move(documentParameters), mediaData);
64
65 TextResourceDecoderForFuzzing decoder(fuzzedData);
66 CString bytes = fuzzedData.ConsumeRemainingBytes();
mmoroz 2016/08/30 19:01:53 Can we estimate how many bytes will be read from t
Charlie Harrison 2016/08/30 19:22:35 Anywhere from 14-78 bytes will be consumed. It's p
67 String decodedBytes = decoder.decode(bytes.data(), bytes.length());
68 scanner->appendToEnd(decodedBytes);
69 scanner->scanAndPreload(&preloader, KURL(), nullptr);
70 return 0;
71 }
72
73 } // namespace blink
74
75 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
76 {
77 return blink::LLVMFuzzerTestOneInput(data, size);
78 }
79
80 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
81 {
82 blink::InitializeBlinkFuzzTest(argc, argv);
83 return 0;
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698