Skip to content

fix(dd): reject oversized block sizes instead of crashing#12887

Open
miniex wants to merge 1 commit into
uutils:mainfrom
miniex:fix/dd-reject-huge-block-size
Open

fix(dd): reject oversized block sizes instead of crashing#12887
miniex wants to merge 1 commit into
uutils:mainfrom
miniex:fix/dd-reject-huge-block-size

Conversation

@miniex

@miniex miniex commented Jun 15, 2026

Copy link
Copy Markdown

Hello, I'm a developer from Korea, so sorry in advance if my English is a bit awkward 🙏

A very large block-size operand (ibs=, obs=, bs=, cbs=) makes dd crash instead of erroring out like GNU does:

# before
$ dd if=a of=b ibs=1778172772721772786161B
thread 'main' panicked at src/uu/dd/src/dd.rs: attempt to multiply with overflow
$ dd if=a of=b obs=1001111111772
memory allocation of 1001111111772 bytes failed
Aborted (core dumped)

# after
$ dd if=a of=b ibs=1778172772721772786161B
dd: invalid number: '1778172772721772786161B': Value too large for defined data type
$ dd if=a of=b obs=1001111111772
dd: IO error: out of memory

What I did:

  • reject a block size >= i64::MAX at parse time, with the same "Value too large for defined data type" message as GNU
  • use saturating_mul for the lcm buffer-size computation so it can't overflow
  • allocate the output buffer with try_reserve, so a too-large obs fails gracefully instead of aborting

I also added regression tests. cargo fmt, clippy (-D warnings) and the dd test suite all pass on my machine (x86_64 Linux).

Fixes #12844
Fixes #12847

A huge ibs=/obs=/bs=/cbs= value used to panic (multiply overflow) or abort
(failed allocation). Reject block sizes >= i64::MAX at parse time like GNU,
and allocate the output buffer with try_reserve.

Fixes uutils#12844, uutils#12847
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/tail/symlink (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/tail-n0f (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/env/env-signal-handler was skipped on 'main' but is now failing.

settings: &settings,
};
let mut output = BufferedOutput::new(inner);
let mut output = BufferedOutput::new(inner).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why using unwrap here?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrap will introduce panics again that is i see, which we want suspose to prevent we spent hours to search for panics, so please do'nt use panic functions handle the Result

@miniex miniex requested a review from sylvestre June 15, 2026 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(dd): when obs= is a very large number it panics bug(dd): when ibs= is a very large number it panics

3 participants