helix icon indicating copy to clipboard operation
helix copied to clipboard

Don't try to open non-regular files

Open mo8it opened this issue 1 year ago • 3 comments

Summary

Helix should only open regular files. Non regular files like devices and pipes should be rejected.

This can be fixed by checking FileType::is_file.

I can open a PR to fix it :)

Reproduction Steps

The following command will freeze and continuously eat RAM.

hx /dev/random

The following command just freezes:

mkfifo pipe
hx pipe

Platform

Relevant on Unix but probably also on Windows

Helix Version

helix 24.3 (f656b4f3)

mo8it avatar May 10 '24 17:05 mo8it

That seems mostly correct and match vim but symlinks should still be opened if they point qt a file or directory. Not sure how is_file handles those

pascalkuthe avatar May 10 '24 17:05 pascalkuthe

fs::metadata traverses symlinks so is_file would return true.

The weird thing is that not every method returning Metadata traverses symlinks. One needs to read its docs. For example, DirEntry::metadata does NOT traverse symlinks.

mo8it avatar May 10 '24 17:05 mo8it

My first thought was "why?" but yeah, the more I think about it, apart from symlinks that point to regular files or directories, I can't think of a use case where any other file type makes sense. Editing a pipe, character device, block device, etc just doesn't make any sense. We need to be able to read the whole file and write back to it, and no other file type fits this pattern.

dead10ck avatar May 10 '24 18:05 dead10ck

I believe this can be closed now since #10733 is merged.

(Off-topic: Congratulations on Rustlings rewrite :))

krish-r avatar Jul 14 '24 08:07 krish-r