Skip to content

the 0x1A stdin truncation is not checksum-specific: 16 line/file applets read stdin in text mode; head gives three different answers #1202

Closed

Description

@caomengxuan666

Summary

The 0x1A stdin truncation is not checksum-specific (that is #1195 / #1200). Sixteen line/file applets read stdin in CRT text mode, so data after 0x1A is dropped and \r\n is collapsed — while the same command reading a file operand is correct. The command disagrees with itself.

Both the niu PATH path and the direct .exe are affected, so this is the applet, not the in-process fast path.

The cleanest single repro: head gives three different answers

Input created with python (not shell escapes): b"abc\x1adef\n".

form bytes out
head f.bin (operand) 61 62 63 1a 64 65 66 0a correct
head < f.bin 61 62 63 truncated at 0x1A
cat f.bin | head 61 62 63 truncated at 0x1A
GNU coreutils, all three forms 61 62 63 1a 64 65 66 0a correct

Direct …\winuxcmd\usr\bin\head.exe produces the same two/one split. Output captured to files and compared with python (not with the in-tree od).

Applets reported in the same class

head tail sort uniq sed grep hexdump xxd fold expand unexpand nl paste fmt pr col

Known-correct reference points in the same tree: cat, tr, od, wc, base64 read binary stdin correctly, and the checksum family is already tracked (#1195, #1200).

Suggested root cause (from the sweep that found it; I have not read the source)

A shared line/file reader used by these applets should set stdin to binary (_O_BINARY / _setmode) once, rather than each command handling it. The already-correct commands above are the reference.

Related

Method

Niubash 1.4.0, Windows 10 x64 (build 19045), winuxcmd 1.1.12; GNU coreutils via WSL; inputs written and outputs compared with python so neither shell escaping nor the in-tree od mediates the bytes.

Activity

  1. added
    bug
    compat-gap
    on Oct 17, 2026
  2. caomengxuan666 commented on Oct 17, 2026

    @caomengxuan666
    MemberAuthor

    The sixteen applets named here are fixed together with the rest of the class in #1218 (branch fix/stdin-binary-sweep), which adds file_io::set_stdin_binary() on each stdin route. See also the follow-up issue #1212.

  3. caomengxuan666 commented on Oct 17, 2026

    @caomengxuan666
    MemberAuthor

    Fixed on master — closing

    a980ea6 fix(stdin): read fd 0 in binary mode across the remaining text-mode applets (#1202, #1212, #1211) (#1218) cites this issue by number, and the patch adds binary-mode stdin handling plus unit tests across the applet set (73 files changed — xxd, nl, paste, unexpand, uniq, sed, sort, tail, strings, …). src/utils/file_io.cppm now does _setmode(_fileno(stdin), _O_BINARY) on the shared read paths (lines 260/271).

    Honest caveat on my verification: I could not build master on this machine (no Visual Studio / CMake here — the documented path is VS 2022 + CMake 3.30 + Ninja), so this is source-level plus your own added tests, not a runtime re-run by me. The build I originally reported against was 1.1.13 (fbdd2ff), which predates a980ea6 — my error, same class as the stale-build mistake I made on two brush reports.

    If you want a runtime confirmation from me, point me at a published binary that includes a980ea6 and I will re-run the original probe (0x1A-truncation across the line/file applets) and report the raw bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcompat-gap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions