Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/uu/tail/src/tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,9 @@ fn bounded_tail(file: &mut File, settings: &Settings) -> UResult<()> {
FilterMode::Bytes(Signum::Positive(count)) if count > &1 => {
// GNU `tail` seems to index bytes and lines starting at 1, not
// at 0. It seems to treat `+0` and `+1` as the same thing.
file.seek(SeekFrom::Start(*count - 1)).unwrap();
// A seek past EOF may fail; fall back to the end so nothing prints.
file.seek(SeekFrom::Start(*count - 1))
.or_else(|_| file.seek(SeekFrom::End(0)))?;
}
_ => {}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/by-util/test_tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,16 @@ fn test_positive_zero_bytes() {
.no_output();
}

/// A `-c +N` offset past the end of a seekable file must not abort.
#[test]
fn test_positive_bytes_past_end_of_file_does_not_panic() {
let (at, mut ucmd) = at_and_ucmd!();
at.write("f", &"a".repeat(1_000_000));
ucmd.args(&["-c", "+18446744073709551615", "f"])
.succeeds()
.no_output();
}

/// Test for reading all but the first NUM lines: `tail -n +3`.
#[test]
fn test_positive_lines() {
Expand Down
Loading