This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jopamer
Recipients jopamer, paul.moore, steve.dower, tim.golden, zach.ware
Date 2018-10-09.13:55:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1539093354.15.0.545547206417.issue34944@psf.upfronthosting.co.za>
In-reply-to
Content
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.)
History
Date User Action Args
2018-10-09 13:55:54jopamersetrecipients: + jopamer, paul.moore, tim.golden, zach.ware, steve.dower
2018-10-09 13:55:54jopamersetmessageid: <1539093354.15.0.545547206417.issue34944@psf.upfronthosting.co.za>
2018-10-09 13:55:54jopamerlinkissue34944 messages
2018-10-09 13:55:54jopamercreate