-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use read(), not statfs(), to detect files that lie about size
Files in some pseudo filesystems, particularly procfs and tracefs on Linux, lie about their file size in stat(2). They claim to have 0 size, but do return data when read() from. Previously, less handled these files by using statfs(2) to check the filesystem type (f_type field). However, there are 2 problems with this approach: - this requires compiling with the Linux "magic.h" header available, and if less is compiled without this header present, it will not have access to the magic numbers that define procfs and tracefs. Such a less binary will not work on these pseudo filesystems - this approach is not resilient to the addition of new filesystems in the future with similar behavior but a new magic number This patch takes a different approach; it takes advantage of the fact that less (usually) read()s 256 bytes from the beginning of the file to determine if the file is binary. The return value of the read() can be compared with the filesize from stat(2) to determine if the latter is untrustworthy. This moves the bin_file() check to happen unconditionally (for regular files, etc.), instead of only happening when the "--force" flag is specified. While this does result in an extra syscall in that particular circumstance, it will result in fewer syscalls overall for the most common scenario of not specifying "--force".
- Loading branch information
1 parent
1dd094e
commit 1fafd96
Showing
5 changed files
with
32 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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