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
The
regexformat checker is registered withraises=re.error, butre.compileraisesRecursionError(not anre.errorsubclass) 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
Expected
The instance should be reported as invalid (not a valid regex), not raise.
Cause
re.compile("(" * 500)raisesRecursionError, which is not a subclass ofre.error, soFormatChecker.checkdoes not convert it into aFormatError.This is the same class of issue as the
OverflowErrorcase in #1526, but a distinct exception type.Versions