Skip to content

regex format checker crashes with RecursionError on deeply nested patterns #1538

Description

@deepakganesh78

The regex format checker is registered with raises=re.error, but re.compile raises RecursionError (not an re.error subclass) when the pattern nesting exceeds the C stack limit. This causes an uncaught exception to propagate from the validator instead of reporting the instance as invalid.

Reproduction

from jsonschema import Draft202012Validator, FormatChecker

v = Draft202012Validator({"format": "regex"}, format_checker=FormatChecker())
list(v.iter_errors("(" * 500))
# RecursionError: maximum recursion depth exceeded

Expected

The instance should be reported as invalid (not a valid regex), not raise.

Cause

re.compile("(" * 500) raises RecursionError, which is not a subclass of re.error, so FormatChecker.check does not convert it into a FormatError.

This is the same class of issue as the OverflowError case in #1526, but a distinct exception type.

Versions

  • jsonschema 4.26.0
  • Python 3.13

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions