Skip to content

Commit

Permalink
[jsoncpp] Fix & add coverage packing (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
Antwy authored Dec 18, 2024
1 parent b57ea11 commit 53d9c6a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions projects/jsoncpp/jsoncpp_fuzz-packer-lf.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

[sydr]
args = "-l debug --solving-timeout 30 -j 2"
target = "/sydr/jsoncpp_proto_fuzz_sydr @@"
target = "/sydr/jsoncpp_fuzz_sydr @@"
jobs = 2

[libfuzzer]
Expand All @@ -25,4 +25,5 @@ args = "-dict=/json.dict /corpus"
proto_packer_path = "/pack/json_packer"

[cov]
target = "/cov/jsoncpp_proto_fuzz_cov @@"
target = "/cov/jsoncpp_fuzz_cov @@"
proto_to_native_cov = true
8 changes: 6 additions & 2 deletions projects/jsoncpp/packer/json_packer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ DEFINE_CONVERT_DATA(json_proto::JsonParseAPI &msg, std::string data) {
data.erase(std::remove(data.begin(), data.end(), ' '), data.end());
size_ = data.size();
jstr_ = data.c_str();

msg.set_settings(1);
// Skip settings bytes if this doesn't look like valid json start.
if (size_ > 4 && jstr_[0] != '{' && jstr_[0] != '[') {
size_ -= sizeof(uint32_t);
jstr_ += sizeof(uint32_t);
}

// Parse Json
std::string n(jstr_, size_);
Expand All @@ -100,6 +103,7 @@ DEFINE_CONVERT_DATA(json_proto::JsonParseAPI &msg, std::string data) {
*av = ParseArrayValue(0, endpos, arena);
st->set_allocated_array_value(av);
}
msg.set_settings(1);
msg.set_allocated_starter(st);
}
else {
Expand Down

0 comments on commit 53d9c6a

Please sign in to comment.