python / python/cpython

Open() on path that exceeds 248 char limit results in "FileNotFoundError: [Errno 2] No such file or directory"

Open
#99,954 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

OS-windows type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

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:

  • 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported behavior on Windows x64 with Python 3.10.4: open a file whose path exceeds 248 characters, then test importing a module from an overlong path appended to sys.path. Trace the open and import failures to identify where the length condition is lost. Done means both cases report an accurate path-length error instead of FileNotFoundError or ModuleNotFoundError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.