Skip to content

dd: don't silently swallow truncate failures#12340

Open
c-tonneslan wants to merge 1 commit into
uutils:mainfrom
c-tonneslan:fix/dd-truncate-error
Open

dd: don't silently swallow truncate failures#12340
c-tonneslan wants to merge 1 commit into
uutils:mainfrom
c-tonneslan:fix/dd-truncate-error

Conversation

@c-tonneslan
Copy link
Copy Markdown

Closes #9745.

Output::truncate was suppressing every error from set_len() by calling .ok(), which the comment justified by pointing at of=/dev/null (where ftruncate returns EINVAL). That also hid real failures like ENOSPC and EROFS, so dd would exit 0 while leaving stale tail bytes in the output file.

Narrow the swallow to InvalidInput (which is what set_len returns on non-regular files) and propagate everything else. of=/dev/null still works, real I/O errors now surface.

$ echo hello | ./target/debug/dd of=/dev/null
0+1 records in
0+1 records out
6 bytes copied, 0.000155542 s, 6.0 kB/s

The wrapper around set_len() was suppressing every error from the
truncate step because set_len() on `/dev/null` returns EINVAL. That
also hid real failures like ENOSPC (disk full) and EROFS (read-only
filesystem), so dd would exit 0 while leaving stale tail bytes in the
output file. Backup scripts trusting dd's exit code would then think
a copy succeeded when it didn't.

Only swallow InvalidInput (the kind ftruncate returns on non-regular
files); everything else propagates up to the caller and dd exits
non-zero.

Verified that `of=/dev/null` still works.

Closes uutils#9745.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/tee/tee is no longer failing!
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Congrats! The gnu test tests/printf/printf-surprise is now passing!
Congrats! The gnu test tests/seq/seq-epipe is now passing!

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: Silent Truncate Error Suppression

1 participant