-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjson_schema_fuzzer.cpp
More file actions
42 lines (38 loc) · 1.24 KB
/
Copy pathjson_schema_fuzzer.cpp
File metadata and controls
42 lines (38 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "fuzz_common.hpp"
#include "foundation/json/json_schema.hpp"
#include <cstddef>
#include <cstdint>
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size)
{
try {
const auto input = lgc::fuzz::inputToString(data, size);
const auto parts = lgc::fuzz::splitInput(input, 2);
auto schema = lgc::JsonSchema::fromJsonString(
parts[0],
lgc::JsonSchemaOptions {
.maxSchemaBytes_ = 64 * 1024,
.maxDepth_ = 32,
.maxNodes_ = 2048,
.maxStringLength_ = 8192,
.allowUnknownKeywords_ = false,
});
if (!schema.isOk())
return 0;
lgc::SchemaValidator validator;
(void)validator.validateText(
parts[1],
*schema,
lgc::ValidationOptions {
.maxDepth_ = 32,
.maxNodes_ = 4096,
.maxErrors_ = 16,
.maxStringLength_ = 8192,
.maxInputBytes_ = 64 * 1024,
});
const auto value = lgc::fuzz::parseJsonOrDiscard(parts[1]);
if (!value.is_discarded())
(void)validator.check(value, *schema);
} catch (...) {
}
return 0;
}