Skip to content

Initialize/Finalize Python multiple time and import _ctypes each time lead to a memory corruption #116467

Description

@vstinner

Example on Windows:

importsubprocessprogram=r"PCbuild\amd64\_testembed_d.exe"cmd= [program, "test_repeated_init_exec", "import _ctypes"]
foriinrange(1, 11):
print(f" == Process #{i} ===")
proc=subprocess.run(cmd)
exitcode=proc.returncodeprint(f"=> exitcode {exitcode}")
ifexitcode:
breakprint()

Output:

vstinner@WIN C:\victor\python\main>python bug.py Running Debug|x64 interpreter...
== Process #1 ===
--- Loop #1 ---
--- Loop #2 ---
--- Loop #3 ---
--- Loop #4 ---
=> exitcode 0
== Process #2 ===
--- Loop #1 ---
--- Loop #2 ---
Assertion failed: PyUnicode_CheckExact(ep->me_key), file C:\victor\python\main\Objects\dictobject.c, line 922
=> exitcode 3

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixestopic-ctypestype-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