Repository navigation
Description
Summary
A " inside a single-quoted word of a for list reaches the loop variable
marked with the DATA_DQUOTE carrier (\u{18}), and the compound array-append
path stores that carrier raw, so the array element silently holds byte
0x18 where bash holds ".
Found while probing array write paths for #616; it is not caused by #616 work
— it reproduces identically on master (6daf8e1) and on the #616 branch.
Reproduction
a=()
for v in 'he said "hi"'; do
a+=("$v")
done
printf '%s' "${a[0]}" | od -An -c| shell | bytes of ${a[0]} |
|---|---|
| GNU bash 5.3.20 | h e s a i d " h i " |
rubash 6daf8e1 |
h e s a i d 030 h i 030 |
030 octal = 0x18 = DATA_DQUOTE (src/executor/markers.rs:89), the carrier
byte that stands in for a double quote in word transport.
declare -p shows it too: rubash prints a=([0]=$'he said \030hi\030') where
GNU prints a=([0]="he said \"hi\"").
Controls (all correct in rubash)
v='he said "hi"'; b=(); b+=("$v"); # correct: " survives
c=("$v"); # correct
for w in 'he said "hi"'; do printf '%s' "$w"; done # correctSo the corruption needs the for-list word as the source and
a+=("$v") as the sink. Dumping $v directly is fine, which is why this is
easy to miss.
Minimal distinguishing pair
v='he said "hi"'; a+=("$v") # OK
for v in 'he said "hi"'; do a+=("$v"); done # corruptedWhat I did not establish
I did not trace the owning GNU function or the exact producer/consumer pair in
rubash's word-transport pipeline, so the root cause below is a hypothesis, not a
verified attribution:
- producer side: the
for-list word for'he said "hi"'appears to carry the
literal"asDATA_DQUOTE(a plain single-quoted assignment does not), i.e.
thefor-list word path marks it, whilev=…'does not; - consumer side: one of the compound array-assignment RHS paths fails to
union-decode the carrier, while the ordinary argument/quote-removal path does.
src/lexer/continuation.rs and the carrier protocol are explicitly
high-risk (#117 family); per AGENTS.md this needs a GNU-source-grounded
attribution (parse.y word assembly / subst.c expansion) before any edit, so
I am reporting rather than patching.
Impact
Silent wrong value (one corrupted byte) for any array built by appending a
for-list element that contains ". Classified P1-high; escalate to P0 if
the maintainers treat silent value corruption as unconditional.
Environment
- rubash
6daf8e1(master) andperf/array-structured-store(identical result) - GNU bash 5.3.20 (Termux/Android aarch64)
Activity
caomengxuan666 commentedon Oct 15, 2026
Fixed by #633.
The fast path bound the loop variable with live lexer carriers instead of the literal text. Two missing finalisation steps, both in
src/executor/command_words.rs:\u{1f}($) was restored, so"(0x18) and backtick (0x1a) carriers survived into the element;QUOTED_WORD_PREFIX(0x1b), sofor v in '~'bound\x1b~.Verified byte-for-byte: 880 generated for-word cases vs GNU, branch 880/880, master 821/880.
fix(lexer): complete the fully-single-quoted for-word fast path (#629) (