Skip to content

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

Description

@gpshead

Bug report

Bug description:

AsObj() and TupleAsObj() in Modules/_tkinter.c convert nested lists and tuples to Tcl lists by plain C recursion with no depth limit, so a recursive or very deeply nested list passed to tk.call(), setvar(), Variable.set() or a widget option overflows the C stack and segfaults.

import tkinter
v = ['a']
v.append(v)
tkinter.Tcl().setvar('x', v)  # Segmentation fault

The same happens with a list nested about 50,000 levels deep (for example one returned by json.loads()), and in the other direction when getvar() reads a Tcl list nested a few hundred thousand levels deep (FromObj()). I'd expect an exception, as _flatten() in the same file already gives with ValueError: nesting too deep in _flatten.

The recursion is old; gh-143310 fixed a different crash in the same code and was backported.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. self-assigned this
    on Oct 22, 2026
  2. added a commit that references this issue on Oct 22, 2026
  3. serhiy-storchaka commented on Oct 22, 2026

    @serhiy-storchaka
    Member

    Tcl itself crashes on deeply nested lists, see for example https://core.tcl-lang.org/tcl/tktview/c31f72813b3966d13deb165f957033d514acd99f. But it is better to prevent what is preventable on our side.

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

Metadata

Metadata

Assignees

Labels

topic-tkintertype-crashA hard crash of the interpreter, possibly with a core dump

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions