Summary
calc_loop_bsize calculates the remaining count=N iflag=count_bytes input budget from bytes written. An expanding conversion can therefore make the subtraction underflow:
|
let bremain: u128 = bmax - wstat.bytes_total; |
Reproducer
$ yes aaaaaaaaaa | head -c 2000 > input.txt
$ cargo run -p uu_dd --release -- if=input.txt of=out.bin conv=block cbs=1024 count=1000 iflag=count_bytes
Before the fix, debug builds panic and release builds report 2+0 records in, consuming 1,024 bytes although the limit is 1,000. GNU consumes exactly 1,000 bytes.
Expected
Calculate the remaining input budget from bytes read.
Summary
calc_loop_bsizecalculates the remainingcount=N iflag=count_bytesinput budget from bytes written. An expanding conversion can therefore make the subtraction underflow:coreutils/src/uu/dd/src/dd.rs
Line 1436 in 058a2a6
Reproducer
Before the fix, debug builds panic and release builds report
2+0 records in, consuming 1,024 bytes although the limit is 1,000. GNU consumes exactly 1,000 bytes.Expected
Calculate the remaining input budget from bytes read.