uutils / uutils/coreutils

dd if=/dev/zero of=sealed shows I/O error only

Open
#13,403 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - dd
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

IO errors on output should spell out the filename (and, whenever ambiguous: the operation, not only writes can fail!)

dd: writing to '/dev/stdout': Operation not permitted
dd: failed to truncate to 512 bytes in output file '/dev/stdout': Operation not permitted

Not merely a bland error:

dd: IO error: Permission denied

Repro:

import subprocess, fcntl, os
fd = os.memfd_create("repro", os.MFD_ALLOW_SEALING)
try:
    os.ftruncate(fd, 512*4)
    fcntl.fcntl(fd, fcntl.F_ADD_SEALS, fcntl.F_SEAL_SHRINK)
    s = lambda *arg: subprocess.run(["/usr/bin/dd", "status=none", "if=/dev/zero", "seek=1", *arg], stdout=fd).returncode
    subprocess.run(["/usr/bin/dd", "--version"])
    EXPECT_OK, EXPECT_FOOTGUN, EXPECT_FAIL = 0, 0, 1
    print(EXPECT_FOOTGUN == s("count=1"))
    print(EXPECT_OK == s("count=1", "of=/dev/stdout", "conv=notrunc"))
    print(EXPECT_FAIL == s("count=1", "of=/dev/stdout"))
    fcntl.fcntl(fd, fcntl.F_ADD_SEALS, fcntl.F_SEAL_GROW)
    print(EXPECT_FAIL == s("count=5"))
    print(EXPECT_FAIL == s("count=5", "of=/dev/stdout", "conv=notrunc"))
finally:
    os.close(fd)
  • I would not worry too much about the first one, maybe GNU implementations can be convinced that this is, and always was, undocumented and unintended, all the way back to 1997
  • drop the status=none and a test like this covers most of what is missed from not checking tests/dd/fail-ftruncate-fstat.sh
  • Related: https://github.com/uutils/coreutils/issues/10579

Contributor guide

Open the contributing guide

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.

Research direction

Start with the dd command's output-error handling and the existing tests/dd/fail-ftruncate-fstat.sh test mentioned in the issue. Run the supplied reproduction, then remove status=none and use an equivalent test to cover the missed cases. Done means output I/O failures identify the filename and, where needed, the operation, with the relevant tests passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
66/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.