tail -c -9223372036854775808 FILE panics with attempt to negate with overflow under overflow-checks.
$ yes | head -c 8192 > f # a regular file LARGER than the block size (~4 KiB)
$ # debug build (overflow-checks on by default) — clean-rebuild to avoid a stale binary
$ cargo build -q -p uu_tail --bin tail
$ ./target/debug/tail -c -9223372036854775808 f >/dev/null
thread 'main' panicked at src/uu/tail/src/tail.rs:472:17:
attempt to negate with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ echo $?
101
Root cause
In bounded_tail, the Bytes(Negative(count)) arm computes the seek offset as -(*count as i64); for count = 9223372036854775808 (2^63), count as i64 is i64::MIN, and negating i64::MIN overflows i64. A debug (or release + -C overflow-checks) build aborts (exit 101); a normal release build wraps silently and exits 0.
|
FilterMode::Bytes(Signum::Negative(count)) => { |
|
if file.seek(SeekFrom::End(-(*count as i64))).is_err() { |
|
file.seek(SeekFrom::Start(0)).unwrap(); |
|
} |
|
limit = Some(*count); |
|
} |
tail -c -9223372036854775808 FILEpanics withattempt to negate with overflowunder overflow-checks.Root cause
In
bounded_tail, theBytes(Negative(count))arm computes the seek offset as-(*count as i64); forcount = 9223372036854775808(2^63),count as i64isi64::MIN, and negatingi64::MINoverflowsi64. A debug (or release +-C overflow-checks) build aborts (exit 101); a normal release build wraps silently and exits 0.coreutils/src/uu/tail/src/tail.rs
Lines 471 to 476 in ddc98c2