Skip to content

for-list word with a double quote leaks the DATA_DQUOTE carrier into compound array append #629

Closed

Description

@caomengxuan666

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   # correct

So 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   # corrupted

What 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 " as DATA_DQUOTE (a plain single-quoted assignment does not), i.e.
    the for-list word path marks it, while v=…' 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) and perf/array-structured-store (identical result)
  • GNU bash 5.3.20 (Termux/Android aarch64)

Activity

  1. added
    bug
    gnu-baseline
    P1-high
    on Oct 15, 2026
  2. caomengxuan666 commented on Oct 15, 2026

    @caomengxuan666
    MemberAuthor

    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:

    1. quote-data carrier decode — only \u{1f} ($) was restored, so " (0x18) and backtick (0x1a) carriers survived into the element;
    2. word-prefix marker drop — a word starting with a quoted tilde keeps QUOTED_WORD_PREFIX (0x1b), so for v in '~' bound \x1b~.

    Verified byte-for-byte: 880 generated for-word cases vs GNU, branch 880/880, master 821/880.

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

    P1-highbuggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions