Skip to content

gh-160176: Fix crash in tkinter on deeply nested or recursive lists - #160177

Open
gpshead wants to merge 1 commit into
python:mainfrom
gpshead:tkinter-asobj-recursion
Open

gpshead wants to merge 1 commit into
python:mainfrom
gpshead:tkinter-asobj-recursion

Conversation

@gpshead

@gpshead gpshead commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Pass a depth through AsObj()/TupleAsObj() and raise ValueError above 1000 levels, the same limit and exception _flatten() uses. A fixed limit rather than a C stack check, because Tcl itself recurses when it builds the string form of a nested list and can overflow at depths Python's stack check would still allow. Converted items are now released on the error path instead of leaked. The reverse direction, FromObj() on a nested Tcl list, gets Py_EnterRecursiveCall() and raises RecursionError.

Lists or tuples nested deeper than 1000 levels that happened to fit on the stack used to convert and now raise ValueError.

Fixes #160176

ANT-2026-7UKC5QED

…ists

Converting a nested list or tuple to a Tcl object now raises ValueError
above 1000 levels, the same limit _flatten() uses.  Converting a deeply
nested Tcl list back to Python now raises RecursionError.
@gpshead
gpshead force-pushed the tkinter-asobj-recursion branch from da7f96a to 2861120 Compare October 22, 2026 04:44
Comment thread Modules/_tkinter.c
Py_DECREF(result);
return Tkinter_Error(tkapp);
}
if (Py_EnterRecursiveCall(" while converting a Tcl list")) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enters and leaves the recursion guard for every element of the list. It would be cheaper to do this once for list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Crash in tkinter when passing a recursive or deeply nested list to Tcl

2 participants