mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
Fix tail -c panics when requested bytes exceed file size (#10268)
* Fix tail -c panics when requested bytes exceed file size * Add tail bytes exceed file size test * Update test to hit block size condition
This commit is contained in:
@@ -473,7 +473,9 @@ fn bounded_tail(file: &mut File, settings: &Settings) {
|
||||
return;
|
||||
}
|
||||
FilterMode::Bytes(Signum::Negative(count)) => {
|
||||
file.seek(SeekFrom::End(-(*count as i64))).unwrap();
|
||||
if file.seek(SeekFrom::End(-(*count as i64))).is_err() {
|
||||
file.seek(SeekFrom::Start(0)).unwrap();
|
||||
}
|
||||
limit = Some(*count);
|
||||
}
|
||||
FilterMode::Bytes(Signum::Positive(count)) if count > &1 => {
|
||||
|
||||
@@ -5040,6 +5040,22 @@ fn tail_n_lines_with_emoji() {
|
||||
.stdout_only("💐\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tail_bytes_exceeds_file_size() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
// Should be > 4096 bytes (block size can vary):
|
||||
at.write("test_file.txt", &"x".repeat(5000));
|
||||
|
||||
ts.ucmd()
|
||||
.arg("-c")
|
||||
.arg("1048576")
|
||||
.arg("test_file.txt")
|
||||
.succeeds()
|
||||
.stdout_only("x".repeat(5000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_follow_pipe_f() {
|
||||
|
||||
Reference in New Issue
Block a user