Skip to content

fix(builtins): read -d multibyte delimiter matches only its word byte - #3958

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3943-read-d-raw-byte-overmatch
Nov 19, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3943-read-d-raw-byte-overmatch

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #3943.

GNU contract

read.def:385+834: the delimiter is the -d WORD's first byte, compared against stream unit-start bytes. Delimiter eth U+00F0 (word bytes C3 B0) keys on 0xC3 — never on the codepoint 0xF0. A lone 0xE9 with -d é never terminates; an emoji (lead byte 0xF0) is read straight through.

Root cause (two codepoint-keyed faces)

  • The inherited-stdin unit walker's delimiter_byte_matches had a byte == delimiter as u8 arm — the char's codepoint truncated to a byte. Emoji lead 0xF0 == codepoint of ð cut the record; lone 0xE9/0xFF/0x80 stopped on every serve.
  • The text-domain single-byte marker form (read_delimiter_single_form) encoded the codepoint byte: after [bug] read -d with a single-byte delimiter >= 0x80 fails on file-backed input under a UTF-8 locale #3944 taught the byte scanners the word byte, a serve whose scan already read through the raw byte was still cut at the TRIM layer (read -d é -n 5 on ab\351cd served 61 62 instead of 61 62 e9 63 64).

Fix

Every text-domain delimiter face keys on the word's first byte (Executor::read_delim_word_byte from #3944, threaded through the free-fn scan chains): unit matching is exact, the single form encodes the word byte, scan_text_record_bytes/joined_delimiter_scan_applies derive from it. Callers without the word keep the legacy derivation.

Verification

… (Refs #3943)

GNU read.def:385+834 compares stream unit-start bytes against the
-d WORD's first byte only — a typed delimiter eth (word bytes C3 B0)
keys on 0xC3 and reads through every 0xF0, emoji lead bytes included;
a lone 0xE9 with -d é never terminates. Rubash's text-domain faces
kept two codepoint-keyed derivations: the inherited-stdin unit walker
matched the delimiter char truncated to a byte (emoji U+1F600 lead
0xF0 == codepoint 0xF0 of ð cut the record; lone 0xE9/0xFF/0x80
stopped on every serve), and the text-domain single-byte marker form
encoded the codepoint — so a serve whose scan had already read
through the raw byte still cut the record at the trim layer
(`read -d é -n 5` on ab\351cd served 61 62 instead of 61 62 e9 63 64).

Every text-domain delimiter face now keys on the -d word's first
byte (Executor::read_delim_word_byte, threaded through the free-fn
scan chains): stdin_unit_is_delimiter/delimiter_byte_matches match
exactly that byte, read_delimiter_single_form encodes it, and
scan_text_record_bytes / joined_delimiter_scan_applies derive their
delim from it. Callers without the word keep the legacy derivation.
The byte-locale and proper-character controls keep byte-for-byte
GNU shape.

Pins: tests/issue3943_read_d_raw_byte_overmatch.rs (fail-first
verified: 5/8 red at 9c520c3, green with the fix). Seed R136-B
12/12 under WSL GNU bash 5.3.20 vs the Linux rubash build. Oracle
citations: read.def:385, read.def:834, read_mbchar delim_ind
pushback (read.def:1193).
@caomengxuan666
caomengxuan666 force-pushed the fix/3943-read-d-raw-byte-overmatch branch from 740442b to 7f7745a Compare November 19, 2026 16:03
The full-suite census runs test stems in parallel processes sharing
the repo cwd: the pins' relative 'f' operands collided with other
stems' files mid-run (CI census 71 vs 62 baseline failures — every
extra failure was one of these pins reading another test's bytes).
Rubash's own behavior was never wrong: the same scripts pass
standalone and the seeds pass 12/12 on the Linux build. issue3944
and issue3945 pins carry the same latent hazard and are scoped the
same way (their merged-face fixup rides the next tests-only PR).
@caomengxuan666
caomengxuan666 force-pushed the fix/3943-read-d-raw-byte-overmatch branch from 3c44e98 to 95ed800 Compare November 19, 2026 16:37
@caomengxuan666
caomengxuan666 merged commit 6bfdb44 into master Nov 19, 2026
8 of 12 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 19, 2026
…IR (#3960)

Follow-up to #3955/#3954 (the same hazard the #3958 branch scoped for its own pins): parallel census stems sharing the repo cwd collided on the pins' relative file operands. Expectations unchanged.
@caomengxuan666
caomengxuan666 deleted the fix/3943-read-d-raw-byte-overmatch branch November 19, 2026 17:29
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.

[bug] read -d with a multibyte delimiter stops on a raw byte equal to the delimiter's codepoint

1 participant