Issue 9908: os.stat() fails on bytes paths under Windows 7 (original) (raw)

Created on 2010-09-21 00:04 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
win7statbytes.patch pitrou,2010-09-21 00:04
Messages (6)
msg117009 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-21 00:04
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
msg117017 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-09-21 02:05
The bug appears to really be limited to Vista?/W7. On WinXP, >>> os.path.exists('c:/programs/python31') True >>> os.path.exists(b'c:/programs/python31') True Has the patch been tested on WinXP to be sure it does not introduce a bug for this?
msg117036 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-21 08:45
> Has the patch been tested on WinXP to be sure it does not introduce a > bug for this? No. Can you?
msg117083 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-09-21 17:12
Only if given a revised 32bit binary (and revised test_os.py). I expect someone else who can will see this.
msg117088 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-09-21 17:59
The patch looks ok to me. I tested it on Server 2003 (same as XP) and it worked fine in addition to Windows 7.
msg117091 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-21 18:19
Ok, I committed the patch in r84956. Thank you for testing.
History
Date User Action Args
2022-04-11 14:57:06 admin set github: 54117
2010-09-21 18:19:40 pitrou set status: open -> closedresolution: fixedmessages: + stage: resolved
2010-09-21 17:59:35 brian.curtin set messages: +
2010-09-21 17:12:23 terry.reedy set messages: +
2010-09-21 08:45:23 pitrou set messages: +
2010-09-21 02:05:59 terry.reedy set nosy: + terry.reedymessages: +
2010-09-21 00:31:28 eric.smith set nosy: + jaraco, eric.smith
2010-09-21 00:04:15 pitrou create