[issue34944] Update _dirnameW to accept long path names

2018-10-09 Thread Joe Pamer


Change by Joe Pamer :


--
keywords: +patch
pull_requests: +9157
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34944] Update _dirnameW to accept long path names

2018-10-09 Thread Joe Pamer


New submission from Joe Pamer :

The fix for issue 32557 updated os__getdiskusage_impl to use _dirnameW for 
obtaining the parent directory of a file. This would cause a regression if the 
path exceeded 260 characters, since _dirnameW currently returns -1 if given a 
path >= MAX_PATH in length.

As suggested in the issue's comments, _dirnameW should be updated to use 
PathCchRemoveFileSpec when available (on Win8.1 or greater) to avoid throwing 
an unnecessary error on a long path.

Note:
If PathCchRemoveFileSpec isn't available, we can call through 
PathRemoveFileSpecW, which is otherwise deprecated. What's interesting there is 
that while the docs say it expects a buffer of size MAX_PATH, analysis of the 
function shows that it doesn't make assumptions about the size of the path 
other than it's less than 32k characters in length. It calls through 
PathCchRemoveFileSpec under the hood on Win8 and greater, passing in 0x8000h as 
the Cch argument. PathCchRemoveFileSpec then scans through the path for '\' via 
wcschr, stops when it hits the last one and inserts a NULL. (Analysis of 
PathRemoveFileSpecW on a Win7 VM shows that it does basically the same thing, 
and is also resilient to paths greater than MAX_PATH in length.)

--
components: Windows
messages: 327402
nosy: jopamer, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Update _dirnameW to accept long path names
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com