Opened 12 minutes ago
#37532 new Bug
GDALRaster._preprocess_input doesn't handle RecursionError from deeply nested JSON
| Reported by: | rishaankgupta | Owned by: | |
|---|---|---|---|
| Component: | GIS | Version: | 6.1 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Problem
GDALRaster._preprocess_input (django/contrib/gis/gdal/raster/source.py:243)
calls json.loads(ds_input) without catching RecursionError. While Python's
json C parser is mostly iterative, json.loads() may still raise
RecursionError rather than JSONDecodeError when input nesting exceeds the
interpreter's recursion limit (the same behavior that motivated the fix in
#37491 / CVE-2026-114582 for ExternalCRSBlocker.check() in
django/contrib/gis/gdal/geojson.py).
Sibling already fixed
ExternalCRSBlocker.check() was patched 9 days ago (commit d3954c9, Nov 12)
to catch RecursionError and reraise as `ValueError("GeoJSON input is nested
too deeply."). The form fields JSONField and HStoreField` also catch
RecursionError (tests/forms_tests/field_tests/test_jsonfield.py:33-39 and
tests/postgres_tests/test_hstore.py:377-382).
GDALRaster._preprocess_input is the direct sibling in the same module area
and missed the same treatment.
Proposed fix
Wrap json.loads(ds_input) in try/except RecursionError and reraise as
ValueError("Raster JSON input is nested too deeply."), mirroring the
geojson.py fix.
Reproduction
Constructing GDALRaster(deeply_nested_json_string) (e.g. via direct API
call or any code path that passes attacker-controlled JSON to GDALRaster)
currently propagates an uncaught RecursionError to the caller. With the
proposed fix, callers receive a ValueError they can handle as a bad-input
condition (the form field already catches ValueError).