|
| static bool | is_local_json_pointer_ref (const rapidjson::Value &ref_value) |
| | Check whether a $ref value is a local JSON Pointer reference. More...
|
| |
| static const rapidjson::Value * | resolve_local_json_pointer_ref (const rapidjson::Document &schema_document, const rapidjson::Value &ref_value) |
| | Resolve a local JSON Pointer $ref against the schema document. More...
|
| |
| static bool | json_schema_has_unsafe_expansion (const rapidjson::Document &schema_document, const rapidjson::Value *node, uint32_t depth_so_far, uint32_t limit, std::unordered_set< const rapidjson::Value * > *visiting) |
| | Check whether any path from a schema node is unsafe for rapidjson schema compilation. More...
|
| |
| static bool | check_json_schema_expansion_depth (const rapidjson::Document &schema_document) |
| | Validate that a JSON Schema can be safely compiled by rapidjson. More...
|
| |
| static bool | parse_json_schema (const char *json_schema_str, size_t json_schema_length, const char *function_name, rapidjson::Document *schema_document) |
| | parse_json_schema will parse a JSON input into a JSON Schema. More...
|
| |
| bool | is_valid_json_schema (const char *document_str, size_t document_length, const char *json_schema_str, size_t json_schema_length, const char *function_name, bool *is_valid, Json_schema_validation_report *validation_report) |
| | This function will validate a JSON document against a JSON Schema using the validation provided by rapidjson. More...
|
| |
| unique_ptr_destroy_only< const Json_schema_validator > | create_json_schema_validator (MEM_ROOT *mem_root, const char *json_schema_str, size_t json_schema_length, const char *function_name) |
| | Create a Json_schema_validator, allocated on a given MEM_ROOT. More...
|
| |
| static bool check_json_schema_expansion_depth |
( |
const rapidjson::Document & |
schema_document | ) |
|
|
static |
Validate that a JSON Schema can be safely compiled by rapidjson.
rapidjson schema compilation expands local $ref by recursively compiling the referenced subschemas. The recursion depth is therefore related to the number of local reference "hops" along the deepest expansion path. This depth can be large even if no referred object has a $ref at its own top level, as long as each referred object contains a nested object with a $ref.
This function checks whether any expansion path exceeds the limit or contains a local $ref cycle. Each step into a nested object/array and each local $ref expansion counts as 1.
It does this by walking JSON-tree edges (object members / array elements) and local $ref edges (JSON pointer references starting with #), with early exit as soon as the limit is exceeded.
If the limit is exceeded (JSON_SCHEMA_MAX_EXPANSION_DEPTH) or a cycle is detected, ER_JSON_DOCUMENT_TOO_DEEP is reported.
- Parameters
-
| schema_document | Parsed JSON schema document. |
- Return values
-
| true | The schema is unsafe and an error was reported. |
| false | No unsafe expansion path was found. |
| static bool json_schema_has_unsafe_expansion |
( |
const rapidjson::Document & |
schema_document, |
|
|
const rapidjson::Value * |
node, |
|
|
uint32_t |
depth_so_far, |
|
|
uint32_t |
limit, |
|
|
std::unordered_set< const rapidjson::Value * > * |
visiting |
|
) |
| |
|
static |
Check whether any path from a schema node is unsafe for rapidjson schema compilation.
The expansion graph consists of:
- JSON-tree edges (object members / array elements), and
- local
$ref edges (local JSON Pointer references).
A path is unsafe if it exceeds the maximum expansion depth, or if it contains a cycle through local $ref edges. Cyclic local references are rejected before constructing rapidjson::SchemaDocument because rapidjson can recurse while compiling such schemas.
- Parameters
-
| schema_document | Parsed JSON schema document (used for resolving $ref). |
| node | The node to start the search from. |
| depth_so_far | Current depth from the schema root. |
| limit | Maximum allowed expansion depth. |
| [in,out] | visiting | Nodes currently on the expansion path. |
- Return values
-
| true | The limit is exceeded along some path, or a cycle was detected. |
| false | No unsafe path was found. |
| constexpr uint32_t JSON_SCHEMA_MAX_EXPANSION_DEPTH = 100 |
|
staticconstexpr |
Maximum "expansion depth" of a JSON Schema during rapidjson schema compilation.
rapidjson schema compilation is recursive. The call stack depth is driven by a combination of:
- JSON nesting within the schema (object members / array elements), and
- local
$ref expansion (compiling referenced subschemas recursively).
This cap bounds the maximum number of edges along any path in the schema's "expansion graph", where both JSON-tree edges and local $ref edges count as 1.
Since MySQL rejects JSON documents deeper than 100 levels (see sql-common/json_syntax_check.cc), schemas requiring more than 100 levels of expansion cannot describe JSON documents supported by MySQL. We therefore use 100 as the single guard limit here as well.