[New-bugs-announce] [issue18199] No long filename support for Windows

Daniel Sturm report at bugs.python.org
Wed Jun 12 17:24:41 CEST 2013


New submission from Daniel Sturm:

Python at the moment does not handle paths with more than MAX_PATH characters well under Windows.

With Windows 7 x64, Python 3.3 32bit, the attached file fails with:
Traceback (most recent call last):
  File ".\filename_bug.py", line 4, in <module>
    os.makedirs(dir)
  File "C:\Python33\lib\os.py", line 269, in makedirs
    mkdir(name, mode)
FileNotFoundError: [WinError 3] The system cannot find the path specified: './aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'

Same things apply to os.rmdir and probably other functions.

The problem is that in posixmodule.c:path_converter (which is used to get the wchar_t* pathname that is expected by the Win32 API) we do have the following check:
        length = PyUnicode_GET_SIZE(unicode);
        if (length > 32767) {
            FORMAT_EXCEPTION(PyExc_ValueError, "%s too long for Windows");
            Py_DECREF(unicode);
            return 0;
        }
        wide = PyUnicode_AsUnicode(unicode);
but the documentation states:
"The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters. This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLength parameter of the GetVolumeInformation function (this value is commonly 255 characters). To specify an extended-length path, use the "\\?\" prefix. For example, "\\?\D:\very long path"."

Source: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

The problem is that we never prepend "\\?\" to the pathname hence getting the old MAX_PATH limit. 

To fix this the easiest solution would be to change the unicode code path of the function to always return an absolute path (relative paths are always limited by MAX_PATH) with \\?\. For optimization we could only do this if the path is longer than 248 (CreateDir has another interesting exception there..) resp. MAX_CHAR characters.

----------
components: Unicode, Windows
files: filename_bug.py
messages: 191033
nosy: Voo, ezio.melotti
priority: normal
severity: normal
status: open
title: No long filename support for Windows
Added file: http://bugs.python.org/file30563/filename_bug.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18199>
_______________________________________


More information about the New-bugs-announce mailing list