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: Segmentation fault when overriding sys.stderr
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, pablogsal, vstinner
Priority: normal Keywords: patch

Created on 2021-03-29 18:42 by pablogsal, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25075 merged pablogsal, 2021-03-29 18:52
PR 25083 merged miss-islington, 2021-03-29 22:39
PR 25084 merged miss-islington, 2021-03-29 22:39
PR 25085 merged pablogsal, 2021-03-29 23:05
Messages (6)
msg389722 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-03-29 18:42
This code crashes (reported by the one and only Matt Wozniski):

import sys
class MyStderr:
    def write(self, s):
        sys.stderr = None
sys.stderr = MyStderr()
1/0

[1]    34112 segmentation fault  ./python.exe lel.py
msg389723 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-03-29 18:43
The problem is that https://github.com/python/cpython/blob/master/Python/pythonrun.c#L1074 doesn't take a strong reference to sys.stderr but code underneath can potentially release the GIL and remove the reference that keeps the object alive.
msg389764 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-03-29 22:38
New changeset 09b90a037d18f5d4acdf1b14082e57bda78e85d3 by Pablo Galindo in branch 'master':
bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075)
https://github.com/python/cpython/commit/09b90a037d18f5d4acdf1b14082e57bda78e85d3
msg389769 - (view) Author: miss-islington (miss-islington) Date: 2021-03-29 23:03
New changeset ba7f8638f93b5d999b25d8556ca19bdc2e12f359 by Miss Islington (bot) in branch '3.8':
bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075)
https://github.com/python/cpython/commit/ba7f8638f93b5d999b25d8556ca19bdc2e12f359
msg389771 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-03-29 23:24
New changeset 2f01c562be913004e1d46fc02705c51b81638d67 by Pablo Galindo in branch '3.7':
[3.7] bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075). (GH-25085)
https://github.com/python/cpython/commit/2f01c562be913004e1d46fc02705c51b81638d67
msg389772 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-03-29 23:24
New changeset ff4715a7332123713de9920e724bb6c412d8ccef by Miss Islington (bot) in branch '3.9':
bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075) (GH-25083)
https://github.com/python/cpython/commit/ff4715a7332123713de9920e724bb6c412d8ccef
History
Date User Action Args
2022-04-11 14:59:43adminsetgithub: 87826
2021-03-29 23:50:17pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-03-29 23:24:37pablogsalsetmessages: + msg389772
2021-03-29 23:24:24pablogsalsetmessages: + msg389771
2021-03-29 23:05:01pablogsalsetpull_requests: + pull_request23833
2021-03-29 23:03:24miss-islingtonsetmessages: + msg389769
2021-03-29 22:39:22miss-islingtonsetpull_requests: + pull_request23832
2021-03-29 22:39:13miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request23831
2021-03-29 22:38:59pablogsalsetmessages: + msg389764
2021-03-29 18:52:46pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request23825
2021-03-29 18:43:40pablogsalsetmessages: + msg389723
2021-03-29 18:42:46pablogsalcreate