Repository navigation
fix(builtins): read -d keys on the option word's first raw byte - #3955
Merged
Merged
Conversation
…3944) GNU builtins/read.def:385 takes the -d delimiter as the option word's FIRST BYTE (delim = (unsigned char)*list_optarg) and read.def:834 compares it against raw stream bytes in every locale. Rubash widened the word to a delimiter CHARACTER instead; a lone byte word >= 0x80 (-d $'\377') widens to a Latin-1 char whose UTF-8 encoding starts with 0xC3, so under a UTF-8 locale the FdRecordScan byte compare keyed on a byte GNU never tests: every file-backed serve (exec 0<file, -u N, while-read <file) cut the record value at the right byte but reported rc 1 and left the descriptor offset past the wrong place — only byte 0xC3 worked end to end. The word's first byte now travels beside the widened char (Executor::read_delim_word_byte, set by every -d parse site, cleared on a fresh read), mirrors onto the fd table for the acquisition (read_input_for_command), and drives FdRecordScan's first_byte; the text-domain derivation (read_delimiter_first_byte) is recorded for the follow-up serves. Callers without the option word (select, mapfile serves) keep the derived form. Pins: tests/issue3944_read_d_word_first_byte.rs (fail-first verified: 6/8 red at 1d85d15, green with the fix). Seed R138-A 12/12 under WSL GNU bash 5.3.20 vs the Linux rubash build. Oracle citations: read.def:385, read.def:834.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3944.
GNU contract
builtins/read.def:385 takes the
-ddelimiter as the option word's FIRST BYTE (delim = (unsigned char)*list_optarg) and read.def:834 compares it against raw stream bytes — in every locale.-d ékeys on 0xC3;-d $'\377'keys on 0x377's byte 0xFF.Root cause
Rubash widened the word to a delimiter CHARACTER (
read_delimiter_char) whose UTF-8 encoding's first byte then droveFdRecordScan's compare. A lone byte word >= 0x80 widens to a Latin-1 char whose encoding starts with 0xC3/0xC2 — a byte GNU never tests for that word. Under a UTF-8 locale every file-backed serve (exec 0<file,-u N,while read; done < file) cut the record VALUE at the right byte but returned rc 1 (delimiter "not found") and left the descriptor offset past the wrong place; only byte 0xC3 worked end to end. The byte-locale faces were correct by accident (the widened char's byte IS the word's byte there).Fix
read_delimiter_first_byte(word)— read.def:385's value from the raw word.-dparse site records it (Executor::read_delim_word_byte); a freshreadclears it.read_input_for_commandmirrors it onto the fd table for the acquisition and retires it after (aselectserve must never key on a stale byte).FdRecordScan::newkeys its first-byte compare on the word byte; callers without the word (select, mapfile) keep the derived form.Verification
tests/issue3944_read_d_word_first_byte.rs: fail-first verified — 6/8 red at 1d85d15, green with the fix.