fix: catch OSError from Path.is_dir() with invalid filenames#5151
Open
12310312long wants to merge 1 commit into
Open
fix: catch OSError from Path.is_dir() with invalid filenames#515112310312long wants to merge 1 commit into
12310312long wants to merge 1 commit into
Conversation
On macOS/Linux, Path.is_dir() can raise OSError (ENAMETOOLONG) when the path is excessively long or malformed. Wrap calls in try/except to prevent crashes and provide a user-friendly warning instead. Closes Aider-AI#5130 Closes Aider-AI#5082 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On macOS/Linux,
Path.is_dir()can raiseOSErrorwithENAMETOOLONG(Errno 63) when the path is excessively long or malformed (e.g., when a long--system-promptvalue ends up as a positional argument). Three locations inmain.pycallPath(fname).is_dir()without protection, causing unhandled crashes.This fix wraps each call site in
try/except OSErrorand provides a user-friendly warning instead of a traceback.Changes
aider/main.py:read_only_fnamesloop: wrap.expanduser().resolve()and.is_dir()in try/except, skip invalid paths with a warningPath(fname).is_dir()in try/except, treat OSError as an invalid pathPath(all_files[0]).is_dir()and.resolve()in try/except, error gracefully on failureRelated Issues
Closes #5130 — Uncaught OSError in pathlib.py line 1222
Closes #5082 — Uncaught OSError in pathlib.py line 841