Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.path.isfile fails on path exactly 260 Chars long in Windows #89176

Closed
ubermidget2 mannequin opened this issue Aug 26, 2021 · 4 comments
Closed

os.path.isfile fails on path exactly 260 Chars long in Windows #89176

ubermidget2 mannequin opened this issue Aug 26, 2021 · 4 comments
Labels
3.9 only security fixes OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@ubermidget2
Copy link
Mannequin

ubermidget2 mannequin commented Aug 26, 2021

BPO 45013
Nosy @pfmoore, @tjguk, @zware, @serhiy-storchaka, @eryksun, @zooba

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2021-09-16.22:56:44.656>
created_at = <Date 2021-08-26.12:41:25.425>
labels = ['type-bug', 'library', '3.9', 'OS-windows']
title = 'os.path.isfile fails on path exactly 260 Chars long in Windows'
updated_at = <Date 2021-09-16.22:56:44.655>
user = 'https://bugs.python.org/ubermidget2'

bugs.python.org fields:

activity = <Date 2021-09-16.22:56:44.655>
actor = 'steve.dower'
assignee = 'none'
closed = True
closed_date = <Date 2021-09-16.22:56:44.656>
closer = 'steve.dower'
components = ['Library (Lib)', 'Windows']
creation = <Date 2021-08-26.12:41:25.425>
creator = 'ubermidget2'
dependencies = []
files = []
hgrepos = []
issue_num = 45013
keywords = []
message_count = 4.0
messages = ['400341', '400342', '400353', '400413']
nosy_count = 7.0
nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'serhiy.storchaka', 'eryksun', 'steve.dower', 'ubermidget2']
pr_nums = []
priority = 'normal'
resolution = 'third party'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue45013'
versions = ['Python 3.9']

@ubermidget2
Copy link
Mannequin Author

ubermidget2 mannequin commented Aug 26, 2021

I saw 33105, but believe this to be a different issue as path length 260 is valid.

I did testing by crafting a path that is exactly 260 by hand - A path 259 in length reports .isfile() as True.

@ubermidget2 ubermidget2 mannequin added 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 26, 2021
@ubermidget2
Copy link
Mannequin Author

ubermidget2 mannequin commented Aug 26, 2021

I saw 33105, but believe this to be a different issue as path length 260 is valid.

I did testing by crafting a path that is exactly 260 by hand - A path 259 in length reports .isfile() as True.

The Stack Error:
[WinError 3] The system cannot find the path specified

@eryksun
Copy link
Contributor

eryksun commented Aug 26, 2021

The legacy maximum buffer size is 260 characters, but remember that strings in C are terminated by a null character (i.e. "\0"). So the maximum path length is actually 259 characters when opening files.

In Windows 10 with Python 3.6+, you can enable the LongPathsEnabled system setting to extend the limit up to about 32760 characters. In many cases you can also use the "\\?\" extended-path prefix to access a long path (e.g. r"\?\C:\some\long\path"), but the path has to be fully qualified and can only use backslash as the separator, not forward slash.

@ubermidget2
Copy link
Mannequin Author

ubermidget2 mannequin commented Aug 27, 2021

What an annoying edge case - makes sense that there isn't an easy fix.

The extended path prefix worked perfectly - thanks

@zooba zooba closed this as completed Sep 16, 2021
@zooba zooba closed this as completed Sep 16, 2021
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants