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

Side by Side Diff: third_party/WebKit/Source/platform/mhtml/MHTMLFuzzer.cpp

Issue 2199493002: libFuzzer for blink::MHTMLParser (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 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 "platform/SharedBuffer.h"
6 #include "platform/heap/Handle.h"
7 #include "platform/mhtml/ArchiveResource.h"
8 #include "platform/mhtml/MHTMLParser.h"
9 #include "platform/testing/TestingPlatformSupport.h"
10 #include "wtf/Assertions.h"
11 #include "wtf/Compiler.h"
12
13 #include <base/command_line.h>
14 #include <base/i18n/icu_util.h>
15
16 #include <memory>
17
18 #include <stddef.h>
19 #include <stdint.h>
20
21
22 namespace blink {
23
24 // Fuzzer for blink::MHTMLParser.
25 int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
26 {
27 MHTMLParser mhtmlParser(SharedBuffer::create(data, size));
28 HeapVector<Member<ArchiveResource>> mhtmlArchives = mhtmlParser.parseArchive ();
29 for (const auto& mhtmlArchive : mhtmlArchives) {
30 // TODO(lukasza): Should MHTMLParser guarantee returning valid data?
31 // ASSERT(mhtmlArchive->url().isValid());
mmoroz 2016/08/01 17:41:37 It would be better to avoid asserts in the target
Łukasz Anforowicz 2016/08/01 21:09:39 I was wondering if for an invalid input, MHTMLPars
32 // ASSERT(!mhtmlArchive->mimeType().isEmpty());
33 ALLOW_UNUSED_LOCAL(mhtmlArchive);
34 }
35
36 // Skipping garbage collection on purpose - it doubles exec/s of libfuzzer r uns.
37 // This probably needs to be uncommented to support -detect_leaks=1 flag.
mmoroz 2016/08/01 17:41:37 Good point. If LSan detects that, we have to enabl
Łukasz Anforowicz 2016/08/01 21:09:39 Ok - done. Also - there is no perf regression eve
38 // mhtmlArchives.clear();
39 // ThreadHeap::collectAllGarbage();
40
41 return 0;
42 }
43
44 } // namespace blink
45
46 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
47 {
48 return blink::LLVMFuzzerTestOneInput(data, size);
49 }
50
51 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
52 {
53 base::CommandLine::Init(*argc, *argv);
54 base::i18n::InitializeICU();
55
56 // Intentional leak - no need to do cleanup as explained in
57 // "Initialization/Cleanup" section of testing/libfuzzer/efficient_fuzzer.md
58 new blink::ScopedUnittestsEnvironmentSetup();
Łukasz Anforowicz 2016/08/01 21:09:39 Ooops. This results in a leak report by libfuzzer
59
60 return 0;
61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698