python-jsonschema / python-jsonschema/jsonschema

regex format checker crashes with RecursionError on deeply nested patterns

Open Beginner friendly
#1,538 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.