Skip to content
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

0.17: Infinite recursion in compilation #420

Closed
audunhalland opened this issue Mar 20, 2023 · 1 comment · Fixed by #525
Closed

0.17: Infinite recursion in compilation #420

audunhalland opened this issue Mar 20, 2023 · 1 comment · Fixed by #525

Comments

@audunhalland
Copy link

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.

@tobz
Copy link
Contributor

tobz commented Mar 21, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants