When passing path to os.listdir that is longer then
MAX_PATH (what is supported in Windows API,
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/fileio/fs/naming_a_file.asp) the
path is truncated at position MAX_PATH=260 and
appended with "/*.*", so underlying Windows API
function FindFirstFileW gets garbage on input:
original path truncated, and symbol "/" is added,
which may not be used as path separator in long path.
I think posix_listdir should or raise error when
getting extra long string, or pass it unchanged to
underlying API.
Affected code is in Modules\posixmodule.c, lines 1470-
1478 (Python 2.4.2).
I think there is enough to change base when
calculating size of allocated memory and copied block
from fixed value of MAX_PATH to length of passed to
function string.
And use os.sep instead of "/", of course.
|