Skip to content

dd: keep unblock state across reads so records are not split at read boundaries - #15876

Open
mavrodikomsd-eng wants to merge 1 commit into
uutils:mainfrom
mavrodikomsd-eng:dd-unblock-record-across-reads
Open

mavrodikomsd-eng wants to merge 1 commit into
uutils:mainfrom
mavrodikomsd-eng:dd-unblock-record-across-reads

Conversation

@mavrodikomsd-eng

Copy link
Copy Markdown

Fixes #15818

unblock() was a stateless helper called once per read buffer and ran buf.chunks(cbs) on that buffer alone, so every buffer was assumed to start at a record boundary. A read ending partway through a record turned the leftover partial chunk into its own short line, and every later record in that buffer was cut at the wrong column (e.g. cbs=80 with the default 512-byte block, or short reads from a pipe), while GNU dd prints one line per record.

The Converter now carries the partial record between calls — the same approach the conv=block path already uses with record_len — and finish() pads the final incomplete record with spaces the way GNU does, which unblock then trims.

Testing: added unit tests in blocks.rs feeding records in several reads: record spanning reads, exact records (no extra newline at EOF), EOF partial record, trailing-space trimming across reads and an all-space record. All 90 dd unit tests and the dd integration tests pass; test_ls::test_ls_hidden_link_windows fails on this branch but also fails on current main (pre-existing Windows failure, unrelated).

…boundaries

unblock() was stateless and ran buf.chunks(cbs) on each read buffer
separately, so every buffer was assumed to start at a record boundary:
a read ending partway through a record turned the leftover into a short
line and cut every later record in that buffer at the wrong column, for
example with cbs=80 and the default 512-byte block, or with short reads
from a pipe.

The Converter now carries the partial record between calls, like the
conv=block path already does, and pads the final incomplete record at
EOF the way GNU dd does.

Fixes uutils#15818

This branch has not been deployed

No deployments
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.

dd: unblock conversion splits records at read boundaries

1 participant