Opened 3 weeks ago

Closed 2 weeks ago

Last modified 2 weeks ago

#37491 closed Bug (fixed)

GeometryField crashes with RecursionError on deeply nested GeoJSON

Reported by: Philip Sørensen Owned by: Bhuvnesh Nama
Component: GIS Version: 5.2
Severity: Release blocker Keywords: GeoJSON
Cc: Philip Sørensen Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Jacob Walls)

The ExternalCRSBlocker.check() added for CVE-2026-111362 (ecb2b77b49) parses GeoJSON input with json.loads() and doesn't catch RecursionError. When the input is nested more deeply than the recursion limit, e.g. a Point with 100,000 nested [ in coordinates, forms.GeometryField.clean() raises RecursionError (HTTP 500) instead of a ValidationError. This also applies to the default widget and the admin. BaseGeometryWidget.deserialize() only catches GEOSException, GDALException, ValueError and TypeError.

On 6.1.2 the same input gives "Invalid geometry value.", so this is a regression in 6.1.3, and presumably 6.0.10 and 5.2.19 too, since the fix was backported.

from django.contrib.gis import forms
n = 100_000
forms.GeometryField().clean('{"type": "Point", "coordinates": ' + "[" * n + "]" * n + "}")
# 6.1.2: ValidationError; 6.1.3 / main: RecursionError

Patch: in ExternalCRSBlocker.check(), re-raise RecursionError from json.loads() as a ValueError, so that it's handled like the JSONDecodeError (a ValueError subclass) that callers already handle. Like #37418, the test mocks json.loads(), because the depth at which it raises depends on the interpreter's stack size.

Change History (13)

comment:1 by Philip Sørensen, 3 weeks ago

Has patch: set

comment:2 by Jacob Walls, 3 weeks ago

Description: modified (diff)
Has patch: unset
Status: assigned → new
Triage Stage: Unreviewed → Accepted
Version: dev → 5.2

Thanks for the report. It makes sense to catch that cleanly. Deassigning due to single PR rate limit.

comment:3 by Jacob Walls, 3 weeks ago

(For me, the provided string does not raise a RecursionError on Python 3.14.10, but I am certain we can find a string that does.)

comment:4 by Jacob Walls, 3 weeks ago

Has patch: set
Keywords: GeoJSON added
Patch needs improvement: set

comment:5 by Bhuvnesh Nama, 3 weeks ago

Owner: set to Bhuvnesh Nama
Status: new → assigned

comment:6 by Bhuvnesh Nama, 3 weeks ago

I've submitted a pull request for this issue:

​https://github.com/django/django/pull/22279

comment:7 by Bhuvnesh Nama, 2 weeks ago

Patch needs improvement: unset

comment:8 by Bhuvnesh Nama, 2 weeks ago

I've updated the PR with the requested changes and pushed the latest commits.

​https://github.com/django/django/pull/22279

comment:9 by Jacob Walls, 2 weeks ago

Triage Stage: Accepted → Ready for checkin

comment:10 by Jacob Walls <jacobtylerwalls@…>, 2 weeks ago

Resolution: → fixed
Status: assigned → closed

In d3954c98:

Fixed #37491 -- Reraised RecursionError as ValueError for deeply nested GeoJSON.

json.loads() raises RecursionError rather than JSONDecodeError when the
input nesting exceeds the interpreter's recursion limit. Reraising as
ValueError allows form fields to reraise as ValidationError.

Regression in ecb2b77b49890d6b2120f73fb3d7eb7ac7650143.

comment:11 by Jacob Walls <jacobtylerwalls@…>, 2 weeks ago

In f3e335f8:

[6.1.x] Fixed #37491 -- Reraised RecursionError as ValueError for deeply nested GeoJSON.

json.loads() raises RecursionError rather than JSONDecodeError when the
input nesting exceeds the interpreter's recursion limit. Reraising as
ValueError allows form fields to reraise as ValidationError.

Regression in ecb2b77b49890d6b2120f73fb3d7eb7ac7650143.

Backport of d3954c981368eb4439be63f2f165d400f33bcd70 from main.

comment:12 by Jacob Walls <jacobtylerwalls@…>, 2 weeks ago

In e7b3cde8:

[6.0.x] Fixed #37491 -- Reraised RecursionError as ValueError for deeply nested GeoJSON.

json.loads() raises RecursionError rather than JSONDecodeError when the
input nesting exceeds the interpreter's recursion limit. Reraising as
ValueError allows form fields to reraise as ValidationError.

Regression in ecb2b77b49890d6b2120f73fb3d7eb7ac7650143.

Backport of d3954c981368eb4439be63f2f165d400f33bcd70 from main.

comment:13 by Jacob Walls <jacobtylerwalls@…>, 2 weeks ago

In 33d2e59:

[5.2.x] Fixed #37491 -- Reraised RecursionError as ValueError for deeply nested GeoJSON.

json.loads() raises RecursionError rather than JSONDecodeError when the
input nesting exceeds the interpreter's recursion limit. Reraising as
ValueError allows form fields to reraise as ValidationError.

Regression in ecb2b77b49890d6b2120f73fb3d7eb7ac7650143.

Backport of d3954c981368eb4439be63f2f165d400f33bcd70 from main.

Note: See TracTickets for help on using tickets.
Back to Top