dd: conv=sync repeats bytes from the previous block when a byte count ends mid-block

Open Beginner friendly
#16,770 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
cli

Research direction

The bug is in fill_blocks in src/uu/dd/src/dd.rs, around lines 553-588, where the read length is compared with the remaining slice length. Run the reproduction from the issue (bs=4 count=5B conv=sync) with the uutils binary and GNU dd and compare the output bytes. Done when the padding after a mid-block end is NUL bytes matching GNU dd, and a dd test covers that case.

Written by the indexing model from the issue text.

Description

With bs=4 count=5B conv=sync, uutils dd writes eight bytes, but the last three repeat bytes 2–4 of the first block. GNU dd pads with three NUL bytes.

Reproduction

Run in an empty directory with the uutils multicall binary as coreutils and GNU dd as dd.

printf ABCDEFGH > input
coreutils dd if=input bs=4 count=5B conv=sync status=none | od -An -tx1
# 41 42 43 44 45 42 43 44
dd if=input bs=4 count=5B conv=sync status=none | od -An -tx1
# 41 42 43 44 45 00 00 00

Verified with official uutils 0.12.0 and 0.13.0 x86_64 Linux musl binaries and GNU coreutils 9.7. Using count=5 iflag=count_bytes gives the same result. With a five-byte input and no count operand, both implementations pad correctly.

Source

On main at 7913995, fill_blocks compares the read length with the remaining slice length. The final one-byte read fills that slice, so it skips padding but advances the output length by four. The unused positions still contain BCD.

https://github.com/uutils/coreutils/blob/791399596cc7214e76c0c6bd022332ab6048ec65/src/uu/dd/src/dd.rs#L553-L588

Related: #13435 corrected input byte-budget accounting. Here the input limit is respected and the output padding is incorrect.

Dominant language
Rust
Stars
24.4k
Forks
2.2k
Avg merge
2d 23h
Merged PRs (30d)
402

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from uutils/coreutils

All issues in uutils/coreutils

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.