[New-bugs-announce] [issue9908] os.stat() fails on bytes paths under Windows 7

Antoine Pitrou report at bugs.python.org
Tue Sep 21 02:04:16 CEST 2010


New submission from Antoine Pitrou <pitrou at free.fr>:

Under Windows 7, there is another path in posixmodule.c for stat() (because of the link dereferencing feature, it seems). This path fails for the bytes version. It turns out that GetFinalPathNameByHandleA returns a value which is one byte too small (while GetFinalPathNameByHandleW returns the expected value). The MSDN doc (*) seems to mention it although with a strange wording:

    “Windows Server 2008 and Windows Vista:  For the ANSI version of this function, GetFinalPathNameByHandleA, the return value includes the size of the terminating null character.”

(*) http://msdn.microsoft.com/en-us/library/aa364962%28VS.85%29.aspx

The net result is that, when we give 'buf_size+1' to the second GetFinalPathNameByHandleA() call after 'buf_size' was returned by the first call, the buffer is still not big enough and it doesn't get filled. The subsequent call to win32_lstat() is done with a bogus path and fails with "[Error 2]: the system cannot find the file specified".

Here is a patch fixing this and also harmonizing win32_stat() and win32_stat_w(). I've added a test, although additional tests for bytes symlinks would probably be deserved. Please review.

PS: the context is:
http://mail.python.org/pipermail/python-dev/2010-September/103860.html

----------
components: Library (Lib), Windows
files: win7statbytes.patch
keywords: patch
messages: 117009
nosy: brian.curtin, db3l, pitrou, tim.golden
priority: high
severity: normal
status: open
title: os.stat() fails on bytes paths under Windows 7
type: behavior
versions: Python 3.2
Added file: http://bugs.python.org/file18940/win7statbytes.patch

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


More information about the New-bugs-announce mailing list