python-jsonschema / python-jsonschema/jsonschema
regex format checker crashes with RecursionError on deeply nested patterns
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5k
- Forks
- 671
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 10
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the regex format checker and FormatChecker.check, then reproduce the failure with the deeply nested pattern shown in the issue. The work is done when that input is reported as an invalid regex through a FormatError rather than propagating RecursionError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100