Skip to content

read -n/-N: limit counts transport units, splitting the last kept carrier pair #714

Closed

Description

@caomengxuan666

Summary

read -n N / -N N counts transport characters, so a carrier pair (U+E000 + U+E0xx, the internal encoding of one raw byte outside the transport set) is counted as two characters. When the limit lands inside a pair, the byte budget lands mid-pair, the cooked half pair gets emitted on the decode channel, and the affected byte shows up as a stray carrier instead of the raw byte.

Environment: found during the fd-0 cursor investigation (PR #711); cross-checked against GNU bash 5.2/5.3.

Repro

printf 'AB\033C' | niu -c '{ read -n3 c; printf %s "$c" | od -An -tx1; }'
# rubash: 41 42 ee 80 80     GNU: 41 42 1b

ESC (0x1B) is transported as a carrier pair; the limit counts the pair as two characters and consumes exactly half of it, leaving the split pair on the stream. read -n3 must emit exactly the first three raw bytes 41 42 1b.

Location & fix shape

src/builtins/read_io.rs (read_function_stdin): the limit check runs on transport text. The limit must count decoded units: one carrier pair consumes one unit of the budget, never can be split.

Dependency

Same read-builtin file as the /dev/stdin + EOF-rc work (rubash#700 / #701). Land that first, or rebase this on it, to avoid colliding in read_io.rs.

Activity

  1. changed the title [-]: limit counts transport units, splitting the last kept carrier pair[/-] [+]read -n/-N: limit counts transport units, splitting the last kept carrier pair[/+] on Oct 17, 2026
  2. added
    bug
    area:read
    area:carrier
    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:carrierarea:readbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions