0.17: Infinite recursion in compilation
Opened this issue · 1 comments
I have a test in my project for infinite data size. This was working well (i.e. not crashing) until the 0.17 upgrade. I'm using Draft202012
for the following schema:
{
"allOf": [
{
"$ref": "#/$defs/1_1"
}
],
"unevaluatedProperties": false,
"$defs": {
"1_1": {
"type": "object",
"properties": {
"b": {
"allOf": [
{
"$ref": "#/$defs/1_2"
}
],
"unevaluatedProperties": false
}
},
"required": [
"b"
]
},
"1_2": {
"type": "object",
"properties": {
"f": {
"allOf": [
{
"$ref": "#/$defs/1_1"
}
],
"unevaluatedProperties": false
}
},
"required": [
"f"
]
}
}
}
I am no jsonschema expert, but I believe this is a valid schema that should accept no JSON documents, because of the required infinite size.
This is certainly related to my PR introducing support for unevaluatedProperties
in #419.
Checking your schema in Hyperjump, it is indeed a valid configuration, and will only emit validation errors at a depth that is correlated with the input itself.
We could likely copy what the $ref
validator itself does, which is to hold on to the relevant compilation context and lazily instantiate validator nodes as needed... which would allow for building the $ref
-specific subvalidator used for unevaluatedProperties
as deep as the input data needs it to be, without recursing infinitely right off the bat.
Definitely a hindsight on my part to not follow what $ref
did from the beginning. I was already looking into another bug that I found with my work on unevaluatedProperties
, so I'll see if I can fix this at the same time.