Skip to content

inline tr fast path: carried control bytes escape [:cntrl:]/[:space:] (payload decoding) #707

Closed

Description

@caomengxuan666

Summary

The inline tr pipeline fast path (src/executor/pipeline_exec.rs:3192, arm
body at 3206-3214, via translate_tr at 3435 and inline_expand_tr_set) walks
input.chars() over the shell's transport text. Control bytes in the carrier
set {0x0c, 0x11, 0x13, 0x14..0x1f} are stored as U+E000 + U+E0xx marker pairs
(substitution_metadata.rs:112, 6 UTF-8 bytes), so they are never members of a
set built from real control characters. [:cntrl:] and [:space:] therefore
skip exactly the carried bytes while mapping the rest.

Classification: payload decoding (carrier pair). Part of the same class as
the tracked wc issue (niubash#383 / rubash#695) — any in-process arm that
classifies input bytes/characters must decode first.

Minimal repro

$ niu -c "printf 'a\033b\nc\n' | tr '[:cntrl:]' X"
a^[bXcX                     # ESC (0x1b) survives
$ <install>/winuxcmd/usr/bin/tr.exe '[:cntrl:]' X < <(printf 'a\033b\nc\n')
aXbXcX
$ D:/Git/bin/bash.exe -c "printf 'a\033b\nc\n' | tr '[:cntrl:]' X"
aXbXcX

Byte evidence (od -An -tu1):

niu   : 97 27 98 88 99 88     # 27 = ESC, unmapped
GNU   : 97 88 98 88 99 88

[:space:] is the same for 0x0c (form feed):

$ niu -c "printf 'a\014b\n' | tr '[:space:]' _"
a\fb_                        # FF survives
$ D:/Git/bin/bash.exe -c "printf 'a\014b\n' | tr '[:space:]' _"
a_b_

Proves the defect is exactly the carrier set: 0x0b (VT) is not carried and
maps correctly, 0x0c is carried and escapes:

$ niu -c "printf 'a\013\014b\n' | tr '[:cntrl:]' X" | od -An -tu1
 97 88 12 98 88              # 0x0b -> X, 0x0c survives
GNU : 97 88 88 98 88

Suggested fix

Decode once at arm entry (shell_text_to_raw_bytes) before set membership, or
make inline_expand_tr_set/translate_tr operate on decoded bytes.

Found by the fast-path differential audit (#706).

Activity

  1. added
    bug
    area:fastpath
    area:carrier
    family:M1
    on Oct 17, 2026
  2. caomengxuan666 commented on Oct 17, 2026

    @caomengxuan666
    MemberAuthor

    已在 d4f0b67(PR #718)修掉,只是 issue 没跟着关。当前 master d248d9f 复验,与 GNU 逐字节一致:

    printf 'a\033b\nc\n' | tr '[:cntrl:]' X   ->  97 88 98 88 99 88
    printf 'a\014b\n'    | tr '[:space:]' _   ->  97 95 98 95
    printf 'a\013\014b\n'| tr '[:cntrl:]' X   ->  97 88 88 98 88
    

    三组在 GNU 上完全相同,carried 的 0x0c/0x13/0x14..0x1f 现在也会先解码再判成员。

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:carrierarea:fastpathbugfamily:M1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions