Repository navigation
fix(digest): read fd 0 in binary mode in the shared hash_file_hex path (#1200) - #1201
Merged
Merged
Conversation
caomengxuan666
force-pushed
the
fix/1200-digest-hash-file-hex-binary
branch
from
October 17, 2026 03:46
c415007 to
5565557
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 old0x1Atruncation here. That is expected, not a regression: my own byte-check on this branch shows md5sum hashing onlyAAAAofAAAA\032BBBB\n. File overlap with #1199 is zero (it owns md5sum/sha1sum/sha256sum/cksum + their tests; this one ownsdigest.cppm/sha512sum/sum + five other test files), so either merge order is conflict-free; #1199-first is only preferred somainnever has a window where those four still truncate. The helper change below is idempotent with #1199's per-tool_setmodecalls.What this PR fixes (the five tools #1200 named)
sha224sum,sha384sum,b2sum, and cksum's portable-a/-croute stream throughportable_digest::hash_file_hex'sstd::cinbranch (src/utils/digest.cppm) — one scoped, idempotent_setmode(_fileno(stdin), _O_BINARY)covers all of them.sha512sumhas its ownfreadstdin 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 _WIN32guards match the repo idiom.Verification (fresh full build, no #1199 in the tree)
Payload
AAAA\032BBBB\n(10 bytes,0x1Amid-payload); GNU referenceD:/Git/usr/bincoreutils;scripts/build-with-vs.ps1→ 836/836.<-ctest -R "sha512sum|sha384sum|sha224sum|b2sum|sum\."→ 192/192 pass, including 21 new*_issue1200tests (mid-payload0x1Avs the GNU digest, NUL handling, pipe-vs-operand equality, plain-text sanity per tool).Notes
_setmodeto_O_BINARYon an already-binary fd 0 is a no-op, so after fix(checksums): read stdin in binary mode so 0x1A no longer truncates input #1199 merges nothing changes for its four tools; if a maintainer prefers one PR to cover both issues, rebasing this onto fix(checksums): read stdin in binary mode so 0x1A no longer truncates input #1199's branch is a clean append.