fix: prevent hang when pasting special files (issue #7683)
This PR fixes a bug where the application would hang if a user pasted a path to a special file (like /dev/tty0 or a named pipe) into the chat composer.
The issue was caused by image::image_dimensions attempting to read from these special files, which can block indefinitely.
Fixes #7683
Changes
- Added
safe_image_dimensionshelper intui/src/clipboard_paste.rs- This function checks std::fs::metadata to ensure the path is a regular file (or symlink to one) before calling image::image_dimensions.
- Updated ChatComposer (
tui/src/bottom_pane/chat_composer.rs) to usesafe_image_dimensionsin:handle_paste_image_path: When handling pasted text.handle_key_event_with_file_popup: When selecting a file from the search popup.
Verification
- Reproduction Test: Created a local reproduction test using a named pipe (FIFO).
- Confirmed that calling image::image_dimensions directly on the FIFO causes a hang (timeout).
- Confirmed that using the new safe_image_dimensions check returns None immediately, preventing the hang.
- Manual Testing: Verified that pasting normal image paths still works as expected.
All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.
I have read the CLA Document and I hereby sign the CLA
recheck
@codex review
Codex Review: Didn't find any major issues. Swish!
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
@Bronx83, can you provide more details about how to repro the problem? We'd like to verify both the problem and the fix, but we've been unable to repro.