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>
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