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

Side by Side Diff: base/json/correctness_fuzzer.cc

Issue 2449323004: json parser/writer correctness fuzzer (Closed)
Patch Set: review Created 4 years, 1 month 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 | « base/BUILD.gn ('k') | no next file » | 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 // A fuzzer that checks correctness of json parser/writer.
6 // The fuzzer input is passed through parsing twice,
7 // so that presumably valid json is parsed/written again.
8
9 #include <stddef.h>
10 #include <stdint.h>
11
12 #include <string>
13
14 #include "base/json/json_reader.h"
15 #include "base/json/json_writer.h"
16 #include "base/json/string_escape.h"
17 #include "base/logging.h"
18 #include "base/values.h"
19
20 // Entry point for libFuzzer.
21 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
22 if (size < 2)
23 return 0;
24
25 int error_code, error_line, error_column;
26 std::string error_message;
27
28 const std::string input_string(reinterpret_cast<const char*>(data), size - 1);
29 const int options = data[size - 1];
danakj 2016/10/29 01:12:42 Still wondering tho, where is this input format fo
aizatsky 2016/10/31 19:56:18 done
30 auto parsed_value = base::JSONReader::ReadAndReturnError(
31 input_string, options, &error_code, &error_message, &error_line,
32 &error_column);
33 if (!parsed_value)
34 return 0;
35
36 std::string parsed_output;
37 bool b = base::JSONWriter::Write(*parsed_value, &parsed_output);
38 LOG_ASSERT(b);
39
40 auto double_parsed_value = base::JSONReader::ReadAndReturnError(
41 parsed_output, options, &error_code, &error_message, &error_line,
42 &error_column);
43 LOG_ASSERT(double_parsed_value);
44 std::string double_parsed_output;
45 bool b2 =
46 base::JSONWriter::Write(*double_parsed_value, &double_parsed_output);
47 LOG_ASSERT(b2);
48
49 LOG_ASSERT(parsed_output == double_parsed_output)
50 << "Parser/Writer mismatch."
51 << "\nInput=" << base::GetQuotedJSONString(parsed_output)
52 << "\nOutput=" << base::GetQuotedJSONString(double_parsed_output);
53
54 return 0;
55 }
OLDNEW
« no previous file with comments | « base/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698