Skip to content

Commit

Permalink
Update src/third_party/libprotobuf-mutator b2c4fb591..b3323e24e
Browse files Browse the repository at this point in the history
Bug: 760280

Change-Id: Ib58b2acfebdf8bee712c1a7d0419874c2044cdfc
Reviewed-on: https://chromium-review.googlesource.com/642460
Reviewed-by: Max Moroz <mmoroz@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#498592}
  • Loading branch information
vitalybuka authored and Commit Bot committed Aug 30, 2017
1 parent 972c76b commit 1a8df4c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 49 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ vars = {
# Three lines of non-changing comments so that
# the commit queue can handle CLs rolling libprotobuf-mutator
# and whatever else without interference from each other.
'libprotobuf-mutator': 'b2c4fb59135711122b800376d8dc46af2fc9d060',
'libprotobuf-mutator': 'b3323e24eca853345cff45c4b3ab89e09d17b9f0',
}

# Only these hosts are allowed for dependencies in this DEPS file.
Expand Down
52 changes: 4 additions & 48 deletions content/test/fuzzer/renderer_proto_tree_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

#include "content/test/fuzzer/fuzzer_support.h"
#include "content/test/fuzzer/html_tree.pb.h"
#include "third_party/libprotobuf-mutator/src/src/binary_format.h"
#include "third_party/libprotobuf-mutator/src/src/libfuzzer/libfuzzer_mutator.h"

protobuf_mutator::protobuf::LogSilencer log_silincer;
#include "third_party/libprotobuf-mutator/src/src/libfuzzer/libfuzzer_macro.h"

namespace content {

Expand Down Expand Up @@ -84,61 +81,20 @@ static void operator<<(HtmlTreeWriter& w, const Document& document) {
w << document.root();
}

static std::string str(const uint8_t* data, size_t size) {
Document document;
protobuf_mutator::ParseBinaryMessage(data, size, &document);

static std::string str(const Document& document) {
HtmlTreeWriter writer;
writer << document;
return writer.str();
// return document.ShortDebugString();
}

extern "C" void LLVMPrintInput(const uint8_t* data, size_t size) {
// fprintf(stderr, "NEW %s\n", str(data, size).c_str());
}

extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data,
size_t size,
size_t max_size,
unsigned int seed) {
fprintf(stderr, "BEFORE %s\n", str(data, size).c_str());
size_t new_size = protobuf_mutator::libfuzzer::MutateBinaryMessage<Document>(
data, size, max_size, seed);
fprintf(stderr, "AFTER %s\n", str(data, new_size).c_str());
return new_size;
}

extern "C" size_t LLVMFuzzerCustomCrossOver(const uint8_t* data1,
size_t size1,
const uint8_t* data2,
size_t size2,
uint8_t* out,
size_t max_out_size,
unsigned int seed) {
fprintf(stderr, "BEFOR1 %s\n", str(data1, size1).c_str());
fprintf(stderr, "BEFOR2 %s\n", str(data2, size2).c_str());
size_t new_size =
protobuf_mutator::libfuzzer::CrossOverBinaryMessages<Document>(
data1, size1, data2, size2, out, max_out_size, seed);
fprintf(stderr, "AFTER %s\n", str(out, new_size).c_str());
return new_size;
}

static Env* env = nullptr;

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
DEFINE_BINARY_PROTO_FUZZER(const Document& document) {
// Environment has to be initialized in the same thread.
if (env == nullptr)
env = new Env();

// str(data, size);

env->adapter->LoadHTML(str(data, size), "http://www.example.org");

// fprintf(stderr, "%s\n", writer.str().c_str());

return 0;
env->adapter->LoadHTML(str(document), "http://www.example.org");
}

} // namespace content
2 changes: 2 additions & 0 deletions third_party/libprotobuf-mutator/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ source_set("libprotobuf-mutator") {
public_configs = [ ":include_config" ]
sources = [
"src/src/binary_format.cc",
"src/src/libfuzzer/libfuzzer_macro.cc",
"src/src/libfuzzer/libfuzzer_mutator.cc",
"src/src/mutator.cc",
"src/src/text_format.cc",
"src/src/utf8_fix.cc",
]
deps = [
"//third_party/protobuf:protobuf_full",
Expand Down

0 comments on commit 1a8df4c

Please sign in to comment.