Skip to content

Commit

Permalink
Revert "Delete unneeded test code from libraries pulled as subtrees (m…
Browse files Browse the repository at this point in the history
…icrosoft#2232)"

This reverts commit 8b07a0e.
  • Loading branch information
jedieaston committed Jul 22, 2022
1 parent 0c8ec54 commit 5387c89
Show file tree
Hide file tree
Showing 252 changed files with 24,981 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[10.0, 20.0, 30.0, 40.0]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1.0, 2.0, 3.0]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1.0, 2.0, 3.0, 4.0]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[10, 20, 30, 40]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1, 2, 3]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1, 2, 3, 4]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["10", "20", "30", "40"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["1", "2", "3"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["1", "2", "3", "4"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"comment": "Document must contain an array of integers, all unique.",
"allOf": [
{
"items": {
"type": "integer"
},
"additionalItems": false,
"type": "array"
},
{
"items": {
"type": "number"
},
"additionalItems": false,
"type": "array",
"uniqueItems": true
}
]
}
43 changes: 43 additions & 0 deletions src/Valijson/valijson/tests/fuzzing/fuzzer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <stdexcept>
#include <unistd.h>

#include <document.h>
#include <valijson/adapters/rapidjson_adapter.hpp>
#include <valijson/utils/rapidjson_utils.hpp>
#include <valijson/schema.hpp>
#include <valijson/schema_parser.hpp>

using valijson::Schema;
using valijson::SchemaParser;
using valijson::adapters::RapidJsonAdapter;

extern "C" int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
if(size<3) return 0;
char input_file[256];
sprintf(input_file, "/tmp/libfuzzer.json");
FILE *fp = fopen(input_file, "wb");
if (!fp)
return 0;
fwrite(data, size, 1, fp);
fclose(fp);

rapidjson::Document schemaDocument;
if (!valijson::utils::loadDocument(input_file, schemaDocument)) {
return 1;
}

Schema schema;
SchemaParser parser;
RapidJsonAdapter schemaDocumentAdapter(schemaDocument);
try {
parser.populateSchema(schemaDocumentAdapter, schema);
} catch (std::exception &e) {
unlink(input_file);
return 1;
}

unlink(input_file);
return 1;
}
32 changes: 32 additions & 0 deletions src/Valijson/valijson/tests/fuzzing/oss-fuzz-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash -eu

# This line causes an abort which breaks fuzzing:
sed -i '27d' include/valijson/utils/rapidjson_utils.hpp

mkdir build
cd build
cmake -Dvalijson_BUILD_EXAMPLES=FALSE \
-Dvalijson_EXCLUDE_BOOST=TRUE \
..

make -j$(nproc)

cd ../tests/fuzzing

find ../.. -name "*.o" -exec ar rcs fuzz_lib.a {} \;

$CXX $CXXFLAGS -DVALIJSON_USE_EXCEPTIONS=1 \
-I/src/valijson/thirdparty/rapidjson-48fbd8c/include \
-I/src/valijson/thirdparty/rapidjson-48fbd8c/include/rapidjson \
-I/src/valijson/include \
-I/src/valijson/include/valijson \
-I/src/valijson/include/valijson/adapters \
-c fuzzer.cpp -o fuzzer.o

$CXX $CXXFLAGS $LIB_FUZZING_ENGINE \
-DVALIJSON_USE_EXCEPTIONS=1 \
-rdynamic fuzzer.o \
-o $OUT/fuzzer fuzz_lib.a

zip $OUT/fuzzer_seed_corpus.zip \
$SRC/valijson/doc/schema/draft-03.json
Loading

0 comments on commit 5387c89

Please sign in to comment.