-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Oss-Fuzz] Adding fuzzer-stl_operations #2160
Closed
Closed
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
f829e72
[Experiment] added a test fuzzer
cd36c9b
[Experiment] edited makefiles to include test fuzzer
a90ff95
[Experiment] corrected a typo in makefile
b95ca37
[Experiment] changed name of test fuzzer
651fb03
[Experiment] renamed again for confirmation
def05d0
[Experiment] temp fuzzer removed
35ce214
fuzzer, testing conversion from vector & deque to json, added
5d501bf
added conversion from other stl sequence containers to json added
74a0470
Added conversion from various maps to json
c66806b
removed namespace bug
57c8851
added parsing from vector and deque
5868e7f
added looping in vector & map, and tested get(), push_back() & emplac…
9388bb2
changed datatype of key in maps from uint8_t to std::string
5c51ebb
initialized json with empty array to test push_back & emplace_back me…
35ac931
resolved all warnings
2efdbfa
removed deque parsing because deque is not a contiguous byte sequence…
6e81c78
[Checking stats] Keeping only conversion from stl containers
tanuj208 c06ee97
[Checking stats] Keeping only iterating a json vector container
tanuj208 02c901e
[Checking stats] Keeping only stl like operations on json vector
tanuj208 2cd4352
[Checking stats] resolved compile error
tanuj208 f3c7022
[Checking stats] Keeping only map coversions to json
tanuj208 f1f38cf
[Checking stats] keeping only stl like operations
tanuj208 a94e1af
[Checking stats] Keeping json map iteration
tanuj208 88194fd
[Checking stats] Keeping only parsing vector
tanuj208 d402b6a
[Checking stats] resolved compiler error
tanuj208 0afebec
Added complete data and renamed files and fuzzer
tanuj208 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
__ _____ _____ _____ | ||
__| | __| | | | JSON for Modern C++ (fuzz test support) | ||
| | |__ | | | | | | version 3.7.3 | ||
|_____|_____|_____|_|___| https://github.com/nlohmann/json | ||
|
||
This file implements test for stl operations suitable for fuzz testing. | ||
|
||
The provided function `LLVMFuzzerTestOneInput` can be used in different fuzzer | ||
drivers. | ||
|
||
Licensed under the MIT License <http://opensource.org/licenses/MIT>. | ||
*/ | ||
|
||
#include <iostream> | ||
#include <deque> | ||
#include <list> | ||
#include <set> | ||
#include <unordered_set> | ||
#include <iterator> | ||
#include <map> | ||
#include <unordered_map> | ||
#include <utility> | ||
#include <sstream> | ||
#include <nlohmann/json.hpp> | ||
|
||
using json = nlohmann::json; | ||
|
||
// see http://llvm.org/docs/LibFuzzer.html | ||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | ||
{ | ||
// putting data in several STL containers | ||
std::vector<uint8_t> vec(data, data + size); | ||
std::deque<uint8_t> deq(data, data + size); | ||
std::list<uint8_t> lst(data, data + size); | ||
std::forward_list<uint8_t> flist(data, data + size); | ||
std::set<uint8_t> st(data, data + size); | ||
std::unordered_set<uint8_t> uset(data, data + size); | ||
std::multiset<uint8_t> multist(data, data + size); | ||
std::unordered_multiset<uint8_t> umultiset(data, data + size); | ||
|
||
// parsing from STL containers | ||
json j_vector(vec); | ||
json j_deque(deq); | ||
json j_list(lst); | ||
json j_flist(flist); | ||
json j_set(st); | ||
json j_uset(uset); | ||
json j_multiset(multist); | ||
json j_umultiset(umultiset); | ||
|
||
// json must be same for sequence containers | ||
assert(j_vector == j_deque); | ||
assert(j_vector == j_list); | ||
assert(j_vector == j_flist); | ||
|
||
// iterating json array and testing get() method | ||
for(json::iterator it = j_vector.begin(); it != j_vector.end(); ++it) | ||
{ | ||
try | ||
{ | ||
int temp = (*it).get<int>(); | ||
} | ||
catch(const json::type_error) | ||
{ | ||
// input might not be convertible to integer | ||
} | ||
} | ||
|
||
for(auto& element : j_vector) | ||
{ | ||
// range-based iteration | ||
} | ||
|
||
json j_vector2 = json::array(); | ||
json j_vector3 = json::array(); | ||
|
||
for(std::size_t i = 0; i < j_vector.size(); ++i) | ||
{ | ||
auto temp = j_vector.at(i); | ||
// testing at() method | ||
j_vector2.push_back(temp); | ||
j_vector3.emplace_back(temp); | ||
// testing push_back and emplace back methods | ||
} | ||
|
||
// these three json vectors must be the same | ||
assert(j_vector == j_vector2); | ||
assert(j_vector == j_vector3); | ||
|
||
std::map<std::string, uint8_t> mp; | ||
std::unordered_map<std::string, uint8_t> umap; | ||
std::multimap<std::string, uint8_t> multimp; | ||
std::unordered_multimap<std::string, uint8_t> umultimap; | ||
|
||
// converting each consecutive entry in the vector into a key-value pair and adding them to map | ||
for(std::size_t i = 1; i < vec.size(); i+=2) | ||
{ | ||
int last_entry = static_cast<int>(vec[i-1]); | ||
std::string key_str = std::to_string(last_entry); | ||
std::pair<std::string, uint8_t> insert_data = std::make_pair(key_str, vec[i]); | ||
mp.insert(insert_data); | ||
umap.insert(insert_data); | ||
multimp.insert(insert_data); | ||
umultimap.insert(insert_data); | ||
} | ||
|
||
// map -> json map | ||
json j_map(mp); | ||
json j_umap(umap); | ||
json j_multimap(multimp); | ||
json j_umultimap(umultimap); | ||
|
||
// iterating json map | ||
for(json::iterator it = j_map.begin(); it != j_map.end(); ++it) | ||
{ | ||
auto temp1 = it.key(); | ||
auto temp2 = it.value(); | ||
} | ||
|
||
try | ||
{ | ||
// parse input directly | ||
json j1 = json::parse(data, data + size); | ||
// parse using vector | ||
json j_vec = json::parse(vec); | ||
|
||
// both of them must be equal | ||
assert(j1 == j_vec); | ||
} | ||
catch (const json::parse_error&) | ||
{ | ||
// parse errors are ok, because input may be random bytes | ||
} | ||
catch (const json::out_of_range&) | ||
{ | ||
// out of range errors may happen if provided sizes are excessive | ||
} | ||
return 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a constructor call, not a parse call. Instead of interpreting the bytes in the containers to create a JSON value, the containers are interpreted as JSON array. As such, no real library code is tested, but just copy/move constructors from STL containers.