Skip to content

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

Merged
gpshead merged 3 commits into
python:mainfrom
gpshead:tkinter-asobj-recursion
Nov 1, 2026
Merged

gpshead merged 3 commits 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 Resolved
@gpshead gpshead removed the needs backport to 3.14 bugs and security fixes label Nov 1, 2026
@gpshead
gpshead enabled auto-merge (squash) November 1, 2026 06:11
@gpshead
gpshead merged commit 9c0cfb1 into python:main Nov 1, 2026
104 of 106 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Sprint Nov 1, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 1, 2026

Copy link
Copy Markdown

GH-161071 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

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