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

Side by Side Diff: net/base/mime_sniffer_fuzzer.cc

Issue 1834303002: Rework the mime sniffer fuzzer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update comment Created 4 years, 8 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
« no previous file with comments | « net/BUILD.gn ('k') | net/base/sniff_mime_type_fuzzer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "net/base/mime_sniffer.h"
6
7 #include <stddef.h>
8 #include <stdint.h>
9
10 #include <string>
11
12 #include "base/strings/string_piece.h"
13 #include "url/gurl.h"
14
15 namespace {
16
17 // Finds the line break in |string_piece|, removes every up to and including the
eroman 2016/03/28 21:00:25 This comment is missing something. removes everyt
mmenke 2016/03/28 21:22:04 Oops. Done. Rewrote this method just a few times
18 // line break from |string_piece|, and returns all the
eroman 2016/03/28 21:00:26 Almost like you ended your thought before - the
mmenke 2016/03/28 21:22:04 That's just silly. The pterodactyl was a Deceptic
19 std::string GetNextArgument(base::StringPiece* string_piece) {
eroman 2016/03/28 21:00:25 not a fan of name "string_piece" |input| would be
mmenke 2016/03/28 21:22:04 Done.
20 base::StringPiece::size_type argument_end = string_piece->find('\n');
21 if (argument_end == base::StringPiece::npos)
22 argument_end = string_piece->size();
23 base::StringPiece argument = string_piece->substr(0, argument_end);
24 *string_piece = string_piece->substr(argument_end + 1);
25 return argument.as_string();
26 }
27
28 } // namespace
29
30 // Fuzzer for the three main mime sniffing functions:
31 // ShouldSniffMimeType, SniffMimeType, and SniffMimeTypeFromLocalData.
32 //
33 // Breaks |data| up into 3 substrings: URL path, MIME type hint, and content,
34 // and passes them to all three MIME type functions (Not all functions take all
35 // arguments). The first two substrings are each on their own line, and content
36 // is everything after them. Since neither URLs nor content-encoding headers can
37 // use line breaks, this doesn't reduce coverage.
38 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
39 base::StringPiece input(reinterpret_cast<const char*>(data), size);
40 // Mime sniffing only cares about the path of a URL, so only take the path
41 // part of the URL from the input.
42 std::string path = GetNextArgument(&input);
43 GURL url("https://unfortunate_site_that_relies_on_mime_sniffing/" + path);
mmenke 2016/03/28 20:20:59 This is a bit unfortunate - it means that a lot of
44
45 std::string mime_type_hint = GetNextArgument(&input);
46
47 net::ShouldSniffMimeType(url, mime_type_hint);
eroman 2016/03/28 21:00:26 This function has a dependence on the URL scheme,
mmenke 2016/03/28 21:22:04 I've switched this to take entire URL. I was taki
mmenke 2016/03/28 21:57:53 And just to confirm, running it now, 90%+ of the t
48
49 std::string result;
50 net::SniffMimeType(input.data(), input.length(), url, mime_type_hint,
eroman 2016/03/28 21:00:26 I presume it may be the case that |!url.is_valid()
mmenke 2016/03/28 21:22:04 So I don't think that case will currently be hit,
51 &result);
52
53 net::SniffMimeTypeFromLocalData(input.data(), input.length(), &result);
54
55 return 0;
56 }
OLDNEW
« no previous file with comments | « net/BUILD.gn ('k') | net/base/sniff_mime_type_fuzzer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698