Skip to content

[compat-gap] in-engine external_cat emulation silently ignores all options (-n/-A/-E lost, -Z not rejected) for bare cat and /bin/cat #415

Closed

Description

@caomengxuan666

Surfaced while attributing niubash#152 (wt42 full-rebaseline lane, 2026-10-02).
Ownership: rubash engine — NOT WinuxCmd, NOT the niu layer.

Reproducer (bare engine, fresh master build dc3e799 worktree)

$ printf 'alpha\nbravo\ncharlie\n' > f.txt
$ rubash.exe -c 'cat -n f.txt'      # no line numbers, rc 0
alpha
bravo
charlie
$ rubash.exe -c 'cat -n f.txt | cat'   # correct — real cat.exe runs in the pipeline stage
     1  alpha
     2  bravo
     3  charlie
$ rubash.exe -c 'cat -Z f.txt'      # unknown option silently accepted, rc 0 (GNU: invalid option, rc 1)

GNU bash + coreutils cat numbers the lines in the first case. Control probes
on the same machine (sort -r, wc -l, grep -n, direct-to-console) all
keep their options — only cat is affected.

Owner

src/executor/external_file_builtins.rs — handle_external_file_builtins()
routes "cat" | "/bin/cat" | "/usr/bin/cat" to the in-engine external_cat()
(match arm at :84; enabled via external_file_builtins_enabled, init.rs:365).
external_cat implements only the -v show-nonprinting family
(cat_has_show_nonprinting / cat_v_filter); -n, -A, -E, -b, -s,
-t, -u, --number, --show-all, ... are silently dropped, and an unknown
option is not rejected. Piped stages bypass the emulation (real subprocess),
which is why the bug only shows when cat's output goes directly to the
shell's stdout/file redirection — the exact pattern niubash#152 characterized.

type -a cat reports /bin/cat (virtual namespace, path.rs
unix_bin_basename), so every bare cat in scripts hits this path.

Fix direction

Either implement the coreutils cat option surface in external_cat
(numbering/show-nonprinting/squeeze/ends, -- handling, unknown-option
diagnostics with GNU wording cat: invalid option -- 'Z' rc 1), or narrow
the emulation's admission (e.g. plain concatenation only; any option word
falls through to the real PATH binary — a false negative there only costs
speed, per the admission-whitelist rule in AGENTS.md).

Cross-links

  • niubash#152 (user-visible report; comment has the attribution chain)
  • Artifacts: target/issue-suites/results/wt42-verify/i152.out

Activity

  1. added 2 commits that reference this issue on Oct 2, 2026
  2. caomengxuan666 commented on Oct 2, 2026

    @caomengxuan666
    MemberAuthor

    Landed as f74e37ac + streaming hotfix dca2e42: external_cat now implements GNU cat's full option surface in-process (parse_cat_argv with GNU's argv permutation and ambiguity ordering; cat_format numbering/-b-wins/$/-s squeeze across operands/-e -t -A compositions; GNU-exact usage diagnostics with possibilities column; --help/--version fall through to the real binary). 174/174 two-shell matrix vs WSL coreutils 9.4. The CI hotfix: the \x27-\x27 operand with identity options and the REAL process stdin streams per chunk (GNU cat.c byte-copy) instead of a buffered drain — the drain deadlocked coproc.tests' interactive coproc { cat - ; } shape (run-coproc exit 124); in-memory sources and formatting keep the bounded drain. Pinned hang test added (two-round write->read interleave). issue415 suite 15/15. niubash#152 closes with this.

  3. added
    bug
    area:fastpath
    on Oct 17, 2026
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

    area:fastpathbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions