classification
Title: 2.6rc2 crashes when trying to open unicode filename with unprintables
Type: Stage:
Components: Windows Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: amaury.forgeotdarc Nosy List: amaury.forgeotdarc, giltay, loewis
Priority: release blocker Keywords: patch

Created on 2008-09-25 15:56 by giltay, last changed 2008-09-25 21:05 by giltay. This issue is now closed.

Files
File name Uploaded Description Edit
unicodecoredump.txt giltay, 2008-09-25 15:56 Core dump from Win2000
invalid_filename.patch amaury.forgeotdarc, 2008-09-25 17:26
Messages (6)
msg73797 - (view) Author: Geoff Gilmour-Taylor (giltay) Date: 2008-09-25 15:56
In 2.6rc2, when I try to open a file with a unicode filename with a tab
in it, Python crashes on Win2000 and WinXP.  Bytestrings raise an
IOError as expected.  I'm using the Windows ia32 binaries.

C:\>c:\python26\python
Python 2.6rc2 (r26rc2:66507, Sep 18 2008, 14:27:33) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('c:\temp\temp.txt')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: invalid filename: c:   emp     emp.txt or mode: r
>>> f = open(u'c:\temp\temp.txt')
[[Crash happens here.]]
C:\>

I also get crashes for other unprintables \a \b \f \n \r \v \x03 and so on.

I'm not getting this on 2.5.2 or 3.0rc1.
msg73804 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-25 17:26
Confirmed here. This also happens on Windows when the mode is invalid:
    open(u"foobar", "rr")

Here is a patch, please review.

The problem does not affect py3k because open() is used in place of
fopen(), and the mode string is parsed differently.
msg73811 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-09-25 20:33
I think it is somewhat surprising that the file name shows up at the end
in the traceback. Instead of getting

IOError: [Errno 22] invalid filename or mode 'w': '/dos/foo\n'

it might be better if it said

IOError: [Errno 22] invalid mode ('w') or filename: '/dos/foo\n'

Otherwise, the patch looks fine.
msg73814 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-25 20:55
Applied patch in r66620, with the suggested change in the error message.
msg73815 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-25 20:55
And, thanks a lot reporting this!
msg73816 - (view) Author: Geoff Gilmour-Taylor (giltay) Date: 2008-09-25 21:05
Cheers.  First bug I've found in 5 years of Python.  (Or, 5 years in and
I still keep forgetting to use raw strings for Windows paths.  :)
History
Date User Action Args
2008-09-25 21:05:02giltaysetmessages: + msg73816
2008-09-25 20:55:46amaury.forgeotdarcsetmessages: + msg73815
2008-09-25 20:55:03amaury.forgeotdarcsetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg73814
keywords: - needs review
2008-09-25 20:33:59loewissetassignee: amaury.forgeotdarc
resolution: accepted
messages: + msg73811
nosy: + loewis
2008-09-25 17:26:46amaury.forgeotdarcsetpriority: release blocker
keywords: + patch, needs review
messages: + msg73804
files: + invalid_filename.patch
nosy: + amaury.forgeotdarc
2008-09-25 15:56:20giltaycreate