[Patches] [ python-Patches-1630975 ] Fix crash when replacing sys.stdout in sitecustomize

SourceForge.net noreply at sourceforge.net
Tue Jan 23 15:02:53 CET 2007


Patches item #1630975, was opened at 2007-01-08 23:55
Message generated for change (Settings changed) made by twouters
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1630975&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core (C code)
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 9
Private: No
Submitted By: Thomas Wouters (twouters)
Assigned to: Thomas Wouters (twouters)
Summary: Fix crash when replacing sys.stdout in sitecustomize

Initial Comment:
When replacing sys.stdout, stderr and/or stdin with non-file, file-like objects in sitecustomize, and also having an environment that makes Python set the encoding of those streams, Python will crash. PyFile_SetEncoding() will be called after sys.stdout/stderr/stdin are replaced, passing the non-file objects.

Fix by not calling PyFile_SetEncoding() in these cases. I'm not entirely sure if we should warn or not; not setting encoding only for replaced streams may cause a disconnect between stdout and stderr that's hard to explain, when someone only replaces one of them (in sitecustomize.) Then again, not many people must be doing it, as it currently just crashes.

No idea how to test for this, from a unittest :P


----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2007-01-17 07:56

Message:
Logged In: YES 
user_id=33168
Originator: NO

Forgot to mention that I agree about the warning.  If no one noticed so
far, this is such an obscure case, it's not that important to warn.  Either
way is fine with me.

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2007-01-17 07:55

Message:
Logged In: YES 
user_id=33168
Originator: NO

I can think of a nasty way to test this, but it's not really worth it. 
You'd need to 'install' your own sitecustomize.py by setting PYTHONPATH and
spawning a python.  Ok, so it's not a real unit test, but it is a test.
:-)

This looks like it will also crash (before and after the patch) if
sys.std{in,out,err} are just deleted rather than replaced (pythonrun.c). 
sysmodule.c looks fine.

I think this is fine for 2.5.1.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1630975&group_id=5470


More information about the Patches mailing list