Commit ecbdfabc authored by Daniel McArdle's avatar Daniel McArdle Committed by Commit Bot

Check serialize/deserialize property in base_json_reader_fuzzer

Change-Id: I686d50b35736fb863ae83bb9a575e6e0cb0a8853
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1790144Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Dan McArdle <dmcardle@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695021}
parent d07eb404
......@@ -3,8 +3,11 @@
// found in the LICENSE file.
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/values.h"
namespace base {
// Entry point for LibFuzzer.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (size < 2)
......@@ -15,11 +18,26 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
std::unique_ptr<char[]> input(new char[size - 1]);
memcpy(input.get(), data, size - 1);
base::StringPiece input_string(input.get(), size - 1);
StringPiece input_string(input.get(), size - 1);
const int options = data[size - 1];
base::JSONReader::ReadAndReturnValueWithError(input_string, options);
JSONReader::ValueWithError json_val =
JSONReader::ReadAndReturnValueWithError(input_string, options);
if (json_val.value) {
// Check that the value can be serialized and deserialized back to an
// equivalent |Value|.
const Value& value = json_val.value.value();
std::string serialized;
CHECK(JSONWriter::Write(value, &serialized));
Optional<Value> deserialized = JSONReader::Read(StringPiece(serialized));
CHECK(deserialized);
CHECK(value.Equals(&deserialized.value()));
}
return 0;
}
} // namespace base
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment