Skip to content

fix(digest): read fd 0 in binary mode in the shared hash_file_hex path (#1200) - #1201

Merged
caomengxuan666 merged 2 commits into
mainfrom
fix/1200-digest-hash-file-hex-binary
Oct 17, 2026
Merged

caomengxuan666 merged 2 commits into
mainfrom
fix/1200-digest-hash-file-hex-binary

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Closes #1200. Follow-up to #1195 / PR #1199 — and depends on it for ordering: this branch is based on main, which does not yet contain #1199, so the four tools #1199 fixes (md5sum/sha1sum/sha256sum/cksum) still show the old 0x1A truncation here. That is expected, not a regression: my own byte-check on this branch shows md5sum hashing only AAAA of AAAA\032BBBB\n. File overlap with #1199 is zero (it owns md5sum/sha1sum/sha256sum/cksum + their tests; this one owns digest.cppm/sha512sum/sum + five other test files), so either merge order is conflict-free; #1199-first is only preferred so main never has a window where those four still truncate. The helper change below is idempotent with #1199's per-tool _setmode calls.

What this PR fixes (the five tools #1200 named)

  • sha224sum, sha384sum, b2sum, and cksum's portable -a/-c route stream through portable_digest::hash_file_hex's std::cin branch (src/utils/digest.cppm) — one scoped, idempotent _setmode(_fileno(stdin), _O_BINARY) covers all of them.
  • sha512sum has its own fread stdin loop (same shape as the md5/sha1/sha256 fix in fix(checksums): read stdin in binary mode so 0x1A no longer truncates input #1199) — same per-tool treatment.
  • sum (SysV CRC) had its own text-mode stdin read — same treatment.

No global fd-0 default is flipped; #ifdef _WIN32 guards match the repo idiom.

Verification (fresh full build, no #1199 in the tree)

Payload AAAA\032BBBB\n (10 bytes, 0x1A mid-payload); GNU reference D:/Git/usr/bin coreutils; scripts/build-with-vs.ps1 → 836/836.

tool pipe < - file operand
sha512sum / sha384sum / sha224sum / b2sum / sum matches GNU (was truncated at 4 bytes) matches matches unchanged
md5sum / sha1sum / sha256sum / cksum still truncated on this branch — fixed by #1199, not here same same unchanged
  • ctest -R "sha512sum|sha384sum|sha224sum|b2sum|sum\." → 192/192 pass, including 21 new *_issue1200 tests (mid-payload 0x1A vs the GNU digest, NUL handling, pipe-vs-operand equality, plain-text sanity per tool).

Notes

@caomengxuan666
caomengxuan666 force-pushed the fix/1200-digest-hash-file-hex-binary branch from c415007 to 5565557 Compare October 17, 2026 03:46
@caomengxuan666
caomengxuan666 merged commit 7cf06a1 into main Oct 17, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1200-digest-hash-file-hex-binary branch October 21, 2026 08:19
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.

sha512sum/sha384sum/sha224sum/b2sum/sum truncate binary stdin at 0x1A (same text-mode root as #1195; shared hash_file_hex path)

1 participant