Mailing List Archive

[issue4071] ntpath.abspath can fail on Win Server 2008 (64-bit)
New submission from Jason Day <jason.day@bluetechllc.com>:

On my system (Windows Server 2008 SP1 - 64-bit, Python 2.5.2 - 32-bit),
simple actions like:
>>> help(help) # Or any function
or
>>> import tempfile
>>> f = tempfile.mktemp()
result in this (rather confusing) error:
TypeError: _getfullpathname() argument 1 must be (buffer overflow), not str

Apparently, _getfullpathname() chokes on certain paths if they are not
supplied as unicode. Locally, I was able to work around the issue by
changing the call to _getfullpathname in ntpath.abspath to:
path = str(_getfullpathname(unicode(path)))

----------
components: Windows
messages: 74502
nosy: JDay
severity: normal
status: open
title: ntpath.abspath can fail on Win Server 2008 (64-bit)
type: crash
versions: Python 2.5

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue4071>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue4071] ntpath.abspath can fail on Win Server 2008 (64-bit) [ In reply to ]
Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment:

The (buffer overflow) message indicates that the argument is too long to
be converted. In your case, it seems that the path is longer than
MAX_PATH=255 characters. What is the value of the argument of _getfullpathname()?

----------
nosy: +amaury.forgeotdarc

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue4071>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue4071] ntpath.abspath can fail on Win Server 2008 (64-bit) [ In reply to ]
Jason Day <jason.day@bluetechllc.com> added the comment:

Running help() or mktemp() causes _getfullpathname to be called with the whole system path (791 characters). If you pass that to _getfullpathname as str it throws the aforementioned TypeError. If it's passed as unicode, it returns an empty string.
The offending _getfullpathname call occurs on the first call to one of these methods. Future calls to either do not call it (unless, of course, the first failed).

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue4071>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue4071] ntpath.abspath can fail on Win Server 2008 (64-bit) [ In reply to ]
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> added the comment:

According to http://msdn.microsoft.com/en-us/library/aa364963.aspx,
current implementation have several problems.

>In the ANSI version of this function, the name is limited to MAX_PATH
>characters. To extend this limit to 32,767 wide characters, call the
>Unicode version of the function and prepend "\\?\" to the path.

:-(

>If the lpBuffer buffer is too small to contain the path, the return
>value is the size, in TCHARs, of the buffer that is required to hold
>the path and the terminating null character.

We should allocate new buffer with this size and retry like already
doing for GetCurrentDirectory.

And one decision problem... What should we do when too long str is
passed to ntpath._getfullpathname? Report overflow error? Or convert to
unicode and retry with GetFullPathNameW? Hmm....

----------
nosy: +ocean-city

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue4071>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue4071] ntpath.abspath can fail on Win Server 2008 (64-bit) [ In reply to ]
Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment:

> Running help() or mktemp() causes _getfullpathname to be called
> with the whole system path (791 characters)

I am not sure to understand. Do you mean the whole PATH environment
variable? I doubt that it is passed to _getfullpathname.
Or do you have very long paths for one directory? the TEMP environment
variable, for example? I'd be curious to see its value.

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue4071>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue4071] ntpath.abspath can fail on Win Server 2008 (64-bit) [ In reply to ]
Jason Day <jason.day@bluetechllc.com> added the comment:

> I am not sure to understand. Do you mean the whole PATH environment
> variable? I doubt that it is passed to _getfullpathname.
> Or do you have very long paths for one directory? the TEMP environment
> variable, for example? I'd be curious to see its value.

I don't have it offhand, but it was the whole PATH environment variable, complete with semicolons. That's probably the *real* bug. Whatever was passing that into abspath didn't seem to mind getting back an empty string (although that may have been further processed in the function, I didn't follow past the call to _getfullpathname).

> And one decision problem... What should we do when too long str is
> passed to ntpath._getfullpathname? Report overflow error? Or convert to
> unicode and retry with GetFullPathNameW? Hmm....

abspath should be able to be called with str or unicode of arbitrary lengths. Consumers of it shouldn't have to be concerned with the platform implementation when it can be smoothed over by the module. Whether this is done in abspath or _getfullpathname probably isn't too important, since end-users generally shouldn't be calling _getfullpathname, directly.

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue4071>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue4071] ntpath.abspath can fail on Win Server 2008 (64-bit) [ In reply to ]
Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment:

> I don't have it offhand, but it was the whole PATH environment
> variable, complete with semicolons. That's probably the *real* bug.

Indeed. Do you happen to have the complete traceback of the failing
tempfile.mktemp() call? I don't see where it can use the PATH
environment variable.

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue4071>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue4071] ntpath.abspath can fail on Win Server 2008 (64-bit) [ In reply to ]
Jason Day <jason.day@bluetechllc.com> added the comment:

> Indeed. Do you happen to have the complete traceback of the failing
> tempfile.mktemp() call? I don't see where it can use the PATH
> environment variable.

The problem was that somehow, on our systems, the TEMP environmental variable had been copied over with PATH. Most likely some batch file tried to store a copy of PATH, without realizing the significance of TEMP. [groan]

Anyway, I still think that it's a bug that abspath() can't be called with a perfectly good str path, because of limitations with the windows api. I edited the bug title to reflect the actual bug.

The str path length could be checked and upgraded to the Unicode version, if necessary (or try again with the unicode version, in the case of an exception). I think it's important to ensure that when abspath() is called with str, it returns str, even if it was upgraded to the unicode call.

----------
title: ntpath.abspath fails for long str paths -> ntpath.abspath can fail on Win Server 2008 (64-bit)

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue4071>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com