Skip to content

dd: count=N iflag=count_bytes underflows when a conversion writes more than N bytes (debug panic, count limit bypassed in release) #13434

Description

@relative23

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions