This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: 2.7 core crashes with generator.gi_frame.f_restricted
Type: Stage: resolved
Components: Interpreter Core Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, ZackerySpytz, doko, eryksun, serhiy.storchaka, terry.reedy, vstinner
Priority: normal Keywords: patch

Created on 2014-11-12 10:20 by doko, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9348 merged ZackerySpytz, 2018-09-17 10:44
Messages (6)
msg231069 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2014-11-12 10:20
seen with the current 2.7 branch:

$ cat > x.py
def foo(): yield
gen = foo()
print gen.gi_frame.f_restricted
for i in gen: pass
print gen.gi_frame
gen = foo()
print gen.next()
print gen.gi_frame.f_restricted

$ python x.py 
False
None
None
Segmentation fault

Program received signal SIGSEGV, Segmentation fault.
0x0000000000462b44 in frame_getrestricted (
    f=Frame 0x7ffff7f58410, for file x.py, line 1, in foo (), closure=0x0)
    at ../Objects/frameobject.c:383
383     ../Objects/frameobject.c: No such file or directory.
(gdb) bt
#0  0x0000000000462b44 in frame_getrestricted (
    f=Frame 0x7ffff7f58410, for file x.py, line 1, in foo (), closure=0x0)
    at ../Objects/frameobject.c:383
msg231072 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2014-11-12 11:38
This is related to the fix for issue 14432. gen_send_ex sets f->f_tstate to NULL, so PyFrame_IsRestricted segfaults: 

    #define PyFrame_IsRestricted(f) \
        ((f)->f_builtins != (f)->f_tstate->interp->builtins)
msg231075 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-11-12 12:57
Related change:

New changeset aa324af42c0e by Victor Stinner in branch '2.7':
Issue #14432: Generator now clears the borrowed reference to the thread state
http://hg.python.org/cpython/rev/aa324af42c0e
msg231186 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-11-14 21:16
This appears to be 2.7 only as 3.4.2 stops on the first print with AttributeError: 'frame' object has no attribute 'f_restricted', which is not a crash.
msg231193 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2014-11-14 22:20
The fix for issue 14432 was applied to 3.3, but I'm pretty sure 2.x PyFrame_IsRestricted is the only problem. Nothing else should see f_tstate when it's NULL. Also, f_tstate was dropped from PyFrameObject in 3.4.
msg327643 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-13 09:25
New changeset 68ddb59417ee0b0dedf5c8b66a304138c9ce0a63 by Serhiy Storchaka (Zackery Spytz) in branch '2.7':
[2.7] bpo-22851: Fix a segfault when accessing generator.gi_frame.f_restricted. (GH-9348)
https://github.com/python/cpython/commit/68ddb59417ee0b0dedf5c8b66a304138c9ce0a63
History
Date User Action Args
2022-04-11 14:58:10adminsetgithub: 67040
2018-10-26 08:14:40serhiy.storchakalinkissue21967 superseder
2018-10-13 09:28:43serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-10-13 09:25:13serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg327643
2018-09-17 10:44:29ZackerySpytzsetnosy: + ZackerySpytz
2018-09-17 10:44:04ZackerySpytzsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request8771
2014-11-15 00:20:17Arfreversetnosy: + Arfrever
2014-11-14 22:20:32eryksunsetmessages: + msg231193
2014-11-14 21:16:38terry.reedysetnosy: + terry.reedy
title: core crashes -> 2.7 core crashes with generator.gi_frame.f_restricted
messages: + msg231186

stage: needs patch
2014-11-12 12:57:50vstinnersetmessages: + msg231075
2014-11-12 11:38:14eryksunsetnosy: + eryksun
messages: + msg231072
2014-11-12 10:26:19vstinnersetnosy: + vstinner
2014-11-12 10:20:31dokocreate