Skip to content

cksum --raw / tree -o / split --filter: stop writing through CRT text mode - #1219

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/write-side-binary-output
Oct 17, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/write-side-binary-output

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

What

Fixes #1214. Three write paths handed their bytes to a CRT stream that was
still in Windows text mode, so every 0x0A in the payload was rewritten
as 0D 0A.

tool before after / GNU
cksum --raw 47 8b 0d 0a 06 (5 bytes) 47 8b 0a 06 (4 bytes)
tree -o FILE CRLF, and no N directories, M files summary LF, summary present (same bytes as stdout)
split --filter=cat child stdin sees a\r\nb\r\nc\r\n a\nb\nc\n

Changes

  • src/commands/cksum.cpp — _setmode(_fileno(stdout), _O_BINARY) in
    run(), next to the existing stdin switch, so fwrite(..., stdout) of a
    raw digest is verbatim (same idiom as sort/uniq/tee/tr/yes).
  • src/commands/tree.cpp — open the -o stream with std::ios::binary
    and emit the summary line in file mode too.
  • src/commands/split.cpp — _setmode(_fileno(pipe), _O_BINARY) after
    _popen() so --filter children receive the exact chunk bytes.

Tests

*_issue1214 unit tests in tests/unit/{cksum,tree,split}:

  • cksum_raw_preserves_0x0a_digest_byte_issue1214 — asserts the 4 raw CRC
    bytes for "x"*66 + "\n" (CRC32 47 8b 0a 06).
  • tree_output_file_is_lf_only_and_keeps_summary_issue1214 — asserts the
    -o file is CR-free and carries the summary, matching stdout.
  • split_filter_pipe_delivers_lf_only_bytes_issue1214 — filter child sees
    a\n / b\n exactly.

Verification

Built with scripts/build-with-vs.ps1 (Release, MSVC) and run through the
winuxcmd-tests target; new tests pass, no pre-existing test in
cksum/tree/split regressed. Bytes were cross-checked against WSL coreutils
9.4 with python (bytes), never with the in-tree od.

Note for reviewers: cksum.cpp is also touched by the parallel stdin-binary
work (#1195/#1199/#1200). This change is strictly the stdout mode line in
run(); it does not touch any reader.

@caomengxuan666

Copy link
Copy Markdown
Member Author

Verification (Release / MSVC, scripts/build-with-vs.ps1):

  • Combined tree with all four sweep fixes applied: ctest 2922/2922 passed
    (full suite; the two lsof internet-filter tests are excluded because they
    hang in this sandbox independent of these changes — that hang was observed
    before any edit here, at test fix(patch,touch,file,timeout): winx5-text batch (#1381/#1382/#1383/#1384) #1399).
  • New *_issue1213/*_issue1214/*_issue1215/*_issue1216 tests: 23/23 pass.
  • Touched-tool suites (od grep diff diff3 sdiff cmp cksum tree split uname arch whoami logname hostid expr date): 322/322 pass.

Bytes were always compared against WSL coreutils 9.4 with python
(bytes), never through the in-tree od.

@caomengxuan666
caomengxuan666 force-pushed the fix/write-side-binary-output branch from 39052f8 to 918e415 Compare October 17, 2026 07:10
@caomengxuan666
caomengxuan666 merged commit 5020be2 into main Oct 17, 2026
4 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/write-side-binary-output branch October 21, 2026 08:20
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.

text-mode writes corrupt output: cksum --raw CRLF-injects 0x0A, tree -o writes CRLF and drops its summary, split --filter pipes CRLF

1 participant