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: Fix filename encoding in PyErr_SetFromWindowsErrWithFilename() (and PyErr_SetExcFromWindowsErrWithFilename())
Type: Stage:
Components: Interpreter Core, Unicode, Windows Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: vstinner
Priority: normal Keywords: patch

Created on 2010-12-27 02:30 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue10780.patch vstinner, 2010-12-27 02:42
issue10780_mbcs_ignore.patch vstinner, 2010-12-27 02:44
Messages (4)
msg124697 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-12-27 02:30
PyErr_SetFromWindowsErrWithFilename() expects a filename encoded to UTF-8. It is called by win32_error() function of the nt (posix) module, and win32_error() is called on an error in the bytes implementation of a function (if the argument is a byte string, not an Unicode string). But on Windows, bytes filenames are encoded to the ANSI code page, not to UTF-8.

PyErr_SetExcFromWindowsErrWithFilename() expects also a filename encoded to UTF-8. It is not used in Python core, but I think that it should be fixed too.

See also #10779 (and #9713 and #10114).
msg124699 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-12-27 02:42
issue10780.patch fixes this issue.
msg124701 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-12-27 02:44
issue10780_mbcs_ignore.patch is a safer but more complex fix: use mbcs decoder with the ignore error handler. Even if issue10780.patch might raise a UnicodeDecodeError, I prefer it because it's shorter, simpler and so easier to maintain the code.
msg124744 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-12-28 00:29
Fixed by r87519.
History
Date User Action Args
2022-04-11 14:57:10adminsetgithub: 54989
2010-12-28 00:29:54vstinnersetstatus: open -> closed

messages: + msg124744
resolution: fixed
2010-12-27 02:44:13vstinnersetfiles: + issue10780_mbcs_ignore.patch

messages: + msg124701
2010-12-27 02:42:08vstinnersetfiles: + issue10780.patch

messages: + msg124699
keywords: + patch
2010-12-27 02:30:42vstinnercreate