[Python-bugs-list] [ python-Bugs-623464 ] tempfile crashes
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 07 Nov 2002 08:12:13 -0800
Bugs item #623464, was opened at 2002-10-15 11:54
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=623464&group_id=5470
Category: Windows
Group: Python 2.3
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Thomas Heller (theller)
Assigned to: Thomas Heller (theller)
Summary: tempfile crashes
Initial Comment:
tempfile.NamedTemporaryFile(".zip") crashes with an
access violation. Win2k, SP2.
----------------------------------------------------------------------
>Comment By: Thomas Heller (theller)
Date: 2002-11-07 17:12
Message:
Logged In: YES
user_id=11105
Sigh, even more work.
In this case, it cannot be called a bugfix anymore...
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2002-11-07 17:08
Message:
Logged In: YES
user_id=31435
Thanks! You certainly need a NEWS item for this, and
possibly even a doc change, since requiring that mode
strings begin with certain letters is a new language
requirement. However unlikely, *somebody* may have code
out there that will break because of it.
----------------------------------------------------------------------
Comment By: Thomas Heller (theller)
Date: 2002-11-07 17:03
Message:
Logged In: YES
user_id=11105
I couldn't get it to crash with Neil's code, so I checked it in
without the Windows #ifdef: posixmodule.c, rev 2.271.
BTW: I always assume we don't need NEWS entries for bug
fixes, is this correct?
----------------------------------------------------------------------
Comment By: Neal Norwitz (nnorwitz)
Date: 2002-11-05 23:33
Message:
Logged In: YES
user_id=33168
Thomas, I belivee the code below will check if the other
cases crash.
# test posixmodule.popen(),
# would need check around line 2835
# as first code in popen()
import posix
# you may need a command that works,
# I'm guessing cmd.exe is ok
posix.popen('cmd.exe', '.zip')
# test socketmodule.sock_makefile(),
# would need check around line 1572
# after PyArg_ParseTuple
from socket import *
s = socket(AF_INET, SOCK_STREAM)
s.makefile('.zip')
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2002-11-05 22:14
Message:
Logged In: YES
user_id=31435
If socketmodule isn't crashing, I'd leave it alone.
----------------------------------------------------------------------
Comment By: Thomas Heller (theller)
Date: 2002-11-05 22:12
Message:
Logged In: YES
user_id=11105
Great, will do this tomorrow. What about socketmodule.c,
which Neal mentioned?
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2002-11-05 22:06
Message:
Logged In: YES
user_id=31435
Cool! One thing: drop the Windows #ifdef. I asked Guido,
and he agrees that Python wants to enforce this requirement
on all platforms.
----------------------------------------------------------------------
Comment By: Thomas Heller (theller)
Date: 2002-11-05 21:40
Message:
Logged In: YES
user_id=11105
Here's a patch for Modules/posixmodule.c, which fixes this
particular issue, conforming to Tim's requirements.
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2002-11-04 23:57
Message:
Logged In: YES
user_id=31435
We generally don't check for valid mode characters
because C allows implementations to extend the standard
set, there's no way to query the platform about which mode
extensions it supports, and we don't want to block users
from using platform-specific mode extensions.
It would be OK by me if we insisted that the first character
be in "rwa", but checking more than that is off limits. Note
that Windows simply ignores all of the mode chars starting
with the first one it doesn't recognize:
>>> f = open('example.txt', 'what a crock this mode string
is!')
>>> f
<open file 'example.txt', mode 'what a crock this mode
string is!' at 0x00651870
>
>>>
That was the same as passing "w".
----------------------------------------------------------------------
Comment By: Neal Norwitz (nnorwitz)
Date: 2002-11-04 21:58
Message:
Logged In: YES
user_id=33168
Sounds good to me. Care to work on a patch with tests?
----------------------------------------------------------------------
Comment By: Thomas Heller (theller)
Date: 2002-11-04 21:36
Message:
Logged In: YES
user_id=11105
IMO we should check for a valid mode. There is a large
surprise if python crashes with an access violation when the
innocent user does innocent things like this. But this is just
*my* opinion.
----------------------------------------------------------------------
Comment By: Neal Norwitz (nnorwitz)
Date: 2002-11-02 21:53
Message:
Logged In: YES
user_id=33168
We don't check anywhere else for valid mode chars. We would
have to fix Modules/posixmodule.c and Modules/socketmodule
if we wanted to check. Thomas, do you think a checks should
be added or close this as a 3rd party problem?
----------------------------------------------------------------------
Comment By: Thomas Heller (theller)
Date: 2002-10-18 10:20
Message:
Logged In: YES
user_id=11105
It crashes in fdopen - looks like a bug in MS runtime library:
(in file vc98\crt\src\fdopen.c)
fdopen calls _tfopen(), creates a FILE *stream, and if the first
character in mode is not r, w, or a, sets 'stream' to NULL to
signal an error. Then it calls _unlock_str(stream), which
crashes.
----------------------------------------------------------------------
Comment By: Neal Norwitz (nnorwitz)
Date: 2002-10-17 23:30
Message:
Logged In: YES
user_id=33168
Note: You probably want:
tempfile.NamedTemporaryFile(suffix=".zip")
I tried this under Linux and get: OSError: [Errno 22]
Invalid argument
So this appears to be windows specific. Exactly which line
is causing the crash? os.fdopen?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=623464&group_id=5470