You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attempting to open or appending paths to sys.path with paths that length exceed the 248 character limit results in incorrect errors. In the case of opening paths that exceeded the limit, rather than an error pointing to the path length being exceeded we see a file not found. A similar error handling issue is prevalent with appending paths that exceed the limit to sys.path. In this case when trying to access the module you will receive a module not found error. I am now aware the path limit can be disabled on installation or later but these false flags led me astray while debugging.
Reproduction Steps:
Create a text file whose path exceeds 248 characters
Attempt to read/write from that file
or
Create a Python module whose path exceeds 248 characters
Attempt to import that module from an external directory by appending the path to sys.path
Environment
CPython versions tested on: 3.10.4
Operating system and architecture: Windows x64
The text was updated successfully, but these errors were encountered:
The legacy path length limit is MAX_PATH - 1 (259) characters. When creating a directory, the legacy limit is MAX_PATH - 12 (248) characters because the system reserves space for a short filename in the directory.
The length limit with long paths enabled -- or for a "\\?\" prefixed path (backslashes only; no forward slashes) -- is about 32760 characters. The length limit for a symlink target is about 4080 characters.
In the case of opening paths that exceeded the limit, rather than an error pointing to the path length being exceeded we see a file not found.
If a path is too long, some WinAPI functions such as SetCurrentDirectoryW() set the last error to ERROR_FILENAME_EXCED_RANGE (206). Other WinAPI functions such as CreateFileW() set the last error to ERROR_PATH_NOT_FOUND (3). The error set for a missing file or directory is ERROR_FILE_NOT_FOUND (2).
The C runtime maps all of these error codes, among others, to the errno value ENOENT, for which Python raises FileNotFoundError.
For example (with support for long paths disabled):
>>> os.chdir('a'*255)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [WinError 206] The filename or extension is too long: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
>>> os.stat('a'*255)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
Bug report
Attempting to open or appending paths to sys.path with paths that length exceed the 248 character limit results in incorrect errors. In the case of opening paths that exceeded the limit, rather than an error pointing to the path length being exceeded we see a file not found. A similar error handling issue is prevalent with appending paths that exceed the limit to sys.path. In this case when trying to access the module you will receive a module not found error. I am now aware the path limit can be disabled on installation or later but these false flags led me astray while debugging.
Reproduction Steps:
or
Environment
The text was updated successfully, but these errors were encountered: