Repository navigation
fix(parser): keep literal 0x1e/0x1f bytes as word data - #3022
Conversation
The lexer marks the quoted spans of a mixed word with in-band `\u{1e}`/`\u{1f}`
markers that `parse_word` turns into per-part quotedness and then consumes.
Single-quoted segments already escaped a marker byte that came from the script
behind the NUL literal sentinel, but unquoted text, double-quoted text,
`${...}` operands, backslash escapes and here-document bodies did not, so the
byte was silently deleted: `printf '[%s]' A<1f>B` printed `[AB]` where bash
prints `[A<1f>B]`. 0x1e and 0x1f are RS and US, ordinary separators in real
data, so reaching this needed no adversarial input.
Every lexer path that copies a literal source character now goes through
`push_literal_char`, and `heredoc_body_escapes` does the same for bodies. A new
bash-oracle test covers both bytes across every quoting context. Subscript text
is deliberately left verbatim: it is handed to arithmetic or associative-key
expansion, which resolve quoting themselves, and `try_parse_assignment` also
recovers a marker-bearing subscript from raw source, so escaping it in the
lexer alone makes assignment and lookup disagree. That pre-existing divergence
is pinned by a test and recorded as a TODO.
Dropping the bytes also broke the fuzz harness' leak attribution, which
compares a builtin's stderr against the script that produced it: nightly
`tomlq_fuzz` ran `tomlq 'target/debug/<1f><1f><1f>deps/'` and the diagnostic
quoted back the banned host path `target/debug/deps/`, a shape the script never
spelled.
The same nightly run tripped a second, independent gap in that attribution.
`script_explains` compared the whole script, padded only at its ends, against a
banned shape, so a shape spelled across the *interior* join between a
diagnostic's template and its echoed operand looked unexplained:
`awk: cmd. line:1: { code:...` and `printf: { code:: invalid number` both
render ` { code:` from the template's `: ` plus an operand the script does
spell. Attribution now decomposes the pattern instead, dropping only the
fragments the `: ` pads could supply and requiring a non-empty core to appear
in the script, so the shapes with no such fragment stay absolute and a format
string that spells a shape itself still fails.
Replays of all three crash units join the existing ones in
`tests/fuzz_crash_regressions.rs`.
Review verdict: approve in spirit, no findings (head
|
The required `msrv` job resolves a fresh external consumer on Rust 1.96.0, deliberately ignoring this repository's Cargo.lock, so it catches dependency floor drift the locked graph hides. markkit 0.3.2 (published today 04:57 UTC, 0.3.3 at 05:57) moved from `mail-parser ^0.11` to `^1.0`, and every mail-parser 1.x declares `rust-version = 1.98`. A fresh resolve therefore picked markkit 0.3.3 -> mail-parser 1.0.2 and the job stopped at `rustc 1.96.0 is not supported by the following package: mail-parser@1.0.2 requires rustc 1.98`. This is time-based, not diff-based: the same job passed on main at 03:06 UTC and `scripts/check-msrv-consumer.py --profile all` fails identically on an unmodified checkout. Cap markkit and markkit-cli below 0.3.2, in lockstep because markkit-cli 0.3.3 requires `markkit ^0.3.3`. The workspace lock already pinned 0.3.1, so Cargo.lock is unchanged and only fresh resolution is constrained. markkit is an optional, off-by-default feature, which is why only the `all` consumer profile was affected. With the cap, `check-msrv-consumer.py --profile all` resolves markkit 0.3.1 and mail-parser 0.11.9 and completes `cargo check` on 1.96.0. The alternative is to raise the consumer floor to 1.98, which drops Rust 1.96 and 1.97 consumers. AGENTS.md says to preserve that floor, so this takes the conservative option; lift the cap when the floor moves on purpose or when markkit's mail-parser dependency supports 1.96 again.
There was a problem hiding this comment.
New push review (head 3e336c9). The core fix is still sound, and the new subscript TODO + pinning test is the right way to scope that gap. But the push also widens the diff to more push_literal_char call sites while leaving sibling raw-copy paths bare, and the knowledge now claims more than the code delivers. Three should-fix items below, all the same bug class as the PR itself (silent 0x1e/0x1f deletion); none is a sandbox/security hole.
| markkit-cli = { version = "0.3.1", default-features = false, features = ["all_formats"], optional = true } | ||
| markkit = { version = "0.3.1", default-features = false, features = ["all_formats"], optional = true } | ||
| # | ||
| # Capped below 0.3.2 to hold the consumer Rust floor. markkit 0.3.2 moved from |
There was a problem hiding this comment.
[P2] Unrelated change in a parser-fix PR: the markkit/markkit-cli <0.3.2 MSRV cap has nothing to do with 0x1e/0x1f handling, is not mentioned in the PR description, and expands the blast radius (dependency resolution for every consumer). Please split it into its own PR or justify it here; per repo guidance PRs should stay small and unrelated changes preserved out.
There was a problem hiding this comment.
Agreed on the principle — this does belong in its own PR, and I raised the same objection myself before adding it. Two corrections and the reason it is here:
It is in the PR description. There is a dedicated "Note on the Rust 1.96 consumer (all) failure" section covering the cause, the evidence and the trade-off. It was added at 10:24 UTC, before this review at 10:33, so the claim that it is unmentioned is out of date.
It is not optional for this PR. markkit 0.3.2 was published today 04:57 UTC (0.3.3 at 05:57) and moved from mail-parser ^0.11 to ^1.0; every mail-parser 1.x declares rust-version = 1.98. The msrv job resolves a fresh consumer while ignoring this repo's Cargo.lock — by design, to catch exactly this drift — so it picked markkit 0.3.3 → mail-parser 1.0.2 and three Rust 1.96 consumer (*, all) jobs went red. Verified it is not this diff:
- the same job passed on
mainat 03:06 UTC, before 0.3.2 existed scripts/check-msrv-consumer.py --profile allfails identically on an unmodified checkout:error: rustc 1.96.0 is not supported ... mail-parser@1.0.2 requires rustc 1.98- with the cap, the same script completes
cargo checkon 1.96.0 in 3m52s
So red CI here was not this PR's doing, but leaving it red would have blocked the merge and main's next run would have hit the same wall.
Blast radius is narrower than it looks. Cargo.lock is unchanged — it already pinned 0.3.1 — so only fresh resolution is constrained and the graph the audit and cargo deny see is identical. markkit is optional and off by default, which is why only the all profile was affected. markkit-cli is capped in lockstep because markkit-cli 0.3.3 requires markkit ^0.3.3.
The alternative is raising the consumer floor to 1.98, which drops Rust 1.96/1.97 consumers; AGENTS.md says to preserve that floor, so this takes the conservative option.
Leaving this thread open: splitting it out needs a second branch, and this session may only push to eve/clever-mccarthy-y66s6i. Maintainer's call whether to split it, keep it, or swap it for a floor bump.
Generated by Claude Code
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 7bc3317 | Commit Preview URL Branch Preview URL |
Nov 26 2026, 11:28 AM |
… escapes Review on #3022 found two more raw-copy paths in the same bug class, both confirmed against real bash before fixing: - Extglob group bodies copied literal source bytes bare, so `@(A<1f>B)` lexed as `@(AB)`. `bash -O extglob` prints `[@(A<1f>B)]`; plain `bash -c` makes `@(` a syntax error, which is why the new test runs the oracle with `-O extglob`. Both the group loop in `read_word_from` and the one embedded in a bracket-pattern word are fixed. A marker is never `(`, `)`, a quote or a backslash, so depth counting, `extglob_escaped` and the `word.pop()` arms are unaffected. - Four backslash arms in the `${...}` readers kept the backslash but pushed the escaped character bare, so `${x:-A\<1f>B}` lost the byte where the `read_dquote_body` analogue now keeps it. Fixed in `read_unquoted_param_body`'s unquoted and double-quote-span arms and `read_param_expansion_into`'s double-quote-span and escape-fallthrough arms, each gated on subscript depth so subscript text stays verbatim. A third finding, markers deleted inside nested `$(...)`/`$((...))`/backtick bodies, did not reproduce: those bodies are copied verbatim and re-lexed when they run, so the second pass escapes their markers. `echo $(echo 'a<1f>b')` already printed `a<1f>b`, matching bash. Added to the oracle test rather than changed. Two divergences deliberately left alone, because bashkit treats *every* character that way and not just these bytes: an unquoted `${x:-A\ZB}` keeps the backslash (bash drops it), and `"${x:-"A\ZB"}"` doubles it. The new test asserts a marker takes the same path as an ordinary character instead of comparing those shapes with bash. Also scope the parser knowledge entry, which claimed "every lexer path" escapes markers. It now lists the covered paths and records the two that copy source verbatim: nested substitution bodies (re-lexed, so markers survive) and subscripts (the deliberate exception).
There was a problem hiding this comment.
Follow-up on head 9e04a0d: the four backslash-arm gaps, the extglob general/backslash arms, and the bracket-word sites from the last review are all fixed with matching tests, and the knowledge now scopes subscripts plus the nested-body story (which I re-verified: Word content is extracted before any stripping, so nested bodies do re-lex intact — withdrawing that item). Two sibling gaps of the same class remain, both one-line fixes in the same pattern as this push.
…on groups Follow-up review on #3022 found two more raw-copy paths, both confirmed against `bash -O extglob` before fixing: - `push_extglob_literal` NUL-shielded only `$` and backtick, so a quoted span inside a group lost the byte while the unquoted group fixed in the last commit kept it: `@('A<1f>B')` and `@("A<1f>B")` lexed as `@(AB)` where bash gives `[@(A<1f>B)]`. Its final push now goes through `push_literal_char`, which adds the sentinel without the backslash a marker does not need. - `read_continuation_into` has its own extglob loop, separate from the `read_word_from` twin, so a group after a quoted start went through the unfixed copy: `"x"*@(a<1f>b)` and `'p'*@(a<1f>b)` lexed as `*@(ab)` where bash keeps the byte. A third item in that review, the `$'...'` ANSI-C backslash arm, is not a bug: `$'A\<1f>B'` already yields `A\<1f>B`, matching bash, because `push_literal_with_escaped_dollar` covers that path. Left alone. `"x"*@(A\<1f>B)` is covered by the character-equivalence test rather than the bash oracle: bashkit keeps the backslash where bash drops it, for every character and not just these bytes, so comparing it with bash would bake an unrelated pre-existing divergence into an expectation.
There was a problem hiding this comment.
Re-review of head 3e7b5e0: both P1 residuals from the last round are fixed in the same pattern as the rest of the push — the continuation-reader extglob loop now uses push_literal_char (with a comment pointing at the read_word_from twin), and push_extglob_literal routes its final push through push_literal_char with a doc comment naming the @('A<1f>B') case. New oracle cases cover the quoted-span and continuation shapes. No new issues found in the four new hunks; the remaining known gaps (subscript verbatim handling, $'...'-backslash micro-case) are pinned or previously noted. No blocking concerns.
Self-review regression. The previous commits escaped marker bytes in
`read_param_expansion_into`'s single-quote span, but that arm serves two
spans with opposite needs, and the `ansi_c` flag already distinguishes them:
- A plain `'...'` span is not decoded again, so it needs the sentinel.
Without it `"${x:-'A<1f>B'}"` yielded `'AB'` where bash gives `'A<1f>B'`.
- An ANSI-C `$'...'` span resolves its own escapes downstream, and that
decode does not consume the sentinel, so escaping there leaked a raw NUL
into the value: `"${x:-$'A<1f>B'}"` became `A\0<1f>B` where bash and the
pre-change behavior both give `A<1f>B`.
The second was a regression this branch introduced on a path that already
worked, and a leaked NUL is worse than the dropped byte it was meant to fix.
No test covered the shape, which is why 7616 passing tests said nothing about
it.
Swept the whole area instead of reasoning case by case: 26 distinct `${...}`,
quoting, extglob and here-document shapes across both marker bytes, each
diffed against real bash and each checked for a stray NUL. All 26 match with
no leaked sentinel. That sweep is what caught the plain-span case still
dropping the byte after the first revert.
Both directions are now pinned, including
`the_literal_sentinel_never_leaks_into_a_value`, since a leaked sentinel is a
distinct failure mode from a dropped byte and nothing guarded it.
There was a problem hiding this comment.
Re-review of head 864da2d: the ANSI-C split is correct and well-explained — plain '...' spans need the sentinel, $'...' spans must not get one since the downstream decode truncates at NUL. The new the_literal_sentinel_never_leaks_into_a_value test pins both halves across 7 shapes. One pre-existing gap in the same span remains (P2 below); everything else from prior rounds stays resolved.
| @@ -2721,7 +2781,19 @@ impl<'a> Lexer<'a> { | |||
| if matches!(q, '{' | '}') { | |||
| content.push('\x00'); | |||
There was a problem hiding this comment.
[P2] Pre-existing, surfacing because this hunk now owns the sentinel-vs-decode contract for this span: the {/} NUL-escape just above is still unconditional, but the ANSI-C decoder (read_dollar_single_quoted_content, :2193-2197) truncates the value at the first NUL ($'x\0y' is x). So ${x:-$'{a}'} decodes the operand $'\0{a\0}' to an empty string where bash gives {a} — silent wrong value, same theme as the marker leak just fixed (sentinel added on a path whose second decode does not consume it). The new sentinel test covers $'A{m}B' but no brace case, so this is untested. Fix needs the brace NUL to be decode-aware (it is load-bearing for the outer ${ brace matching, so it cannot simply be dropped like the marker sentinel was); if that is too much for this PR, a pinning test or a knowledge note would do.
There was a problem hiding this comment.
Real bug, confirmed pre-existing — but the failure mode is the opposite of the predicted one, so recording what I actually measured.
It does not truncate to empty. The sentinels leak into the value, exactly like the marker leak just fixed:
unset x; printf '[%s]' "${x:-$'{a}'}" bashkit: [\0{a\0}] bash: [{a}]
unset x; printf '[%s]' "${x:-$'{a'}" bashkit: [\0{a] bash: [{a]
unset x; printf '[%s]' ${x:-$'{a}'} bashkit: [{a}] bash: [{a}] <- unquoted already correct
So only the double-quoted operand leaks. Your reasoning about read_dollar_single_quoted_content truncating at NUL is right on its own ($'x\0y' is x), but that is not the decode this path takes — the NULs survive to the value instead.
Pre-existing confirmed: identical byte for byte with origin/main's lexer swapped in, so nothing on this branch caused or worsened it.
Taking your "a pinning test or a knowledge note would do" option rather than fixing it here. Three reasons: it is brace escaping rather than marker handling; it cannot be fixed the way the marker sentinel was, since that escape is load-bearing for the outer ${ brace matching ("${v-\}}"), so it has to become decode-aware; and this PR has already absorbed two off-scope items.
Added:
brace_in_an_ansi_c_operand_leaks_the_sentinel_a_known_divergence, pinning both the leaking double-quoted form and the already-correct unquoted one, with bash's values in the message- a paragraph in
knowledge/foundations/parser.mdstating the sentinel-vs-second-decode contract for this span, why the brace escape still violates it, and why dropping it is not the fix
Leaving this thread open so the follow-up stays visible to the maintainer.
Generated by Claude Code
…ands Review on #3022 flagged the `{`/`}` NUL-escape in `read_param_expansion_into`'s quote span. It is a real bug, pre-existing (byte-for-byte identical with `origin/main`'s lexer swapped in), and the failure mode is not the predicted truncation but the same leak the previous commit fixed for markers: "${x:-$'{a}'}" -> \0{a\0} bash: {a} "${x:-$'{a'}" -> \0{a bash: {a ${x:-$'{a}'} -> {a} bash: {a} (unquoted already correct) `read_dollar_single_quoted_content` does truncate at NUL (`$'x\0y'` is `x`), but that is not the decode this path takes; the NULs survive into the value. Not fixed here. It is brace escaping rather than marker handling, and unlike the marker sentinel it cannot be fixed by not adding it: that escape is load-bearing for the outer `${` brace matching (`"${v-\}}"`), so it has to become decode-aware instead. Pinned with bash's values in the assertion messages, and the knowledge entry now states the sentinel-vs-second-decode contract for this span, why the brace escape still violates it, and why dropping it is not the fix.
There was a problem hiding this comment.
Re-review of head 7bc3317: behavior-neutral delta — I diffed every lexer hunk against the previous round and they are byte-identical, so no new parser behavior. The push pins the P2 (${x:-$'{a}'} brace/sentinel leak) as a named known-divergence test asserting exact bytes for quoted vs unquoted operands, with a comment claiming main-identical output, plus a matching parser.md note that correctly states why the brace escape cannot simply be dropped. That is the resolution I offered; no new issues. Nothing blocking.
What changed
Two fixes, one per commit.
1.
fix(parser)— a literal 0x1e/0x1f byte written in a script is now word data everywhere instead of being silently deleted. The lexer uses those bytes as in-band quote-boundary markers; single-quoted segments already escaped a script-supplied marker behind the NUL sentinel, but unquoted text, double-quoted text,${...}operands, backslash escapes and here-document bodies did not. 0x1e and 0x1f are RS and US, ordinary separators in real data, so this needed no adversarial input —IFS=$'\x1f'worked but a literal separator in a word did not.This also closes two paths that let nightly
Fuzz Testinggo red:script_explainscould not attribute a banned shape spelled across the interior join between a diagnostic's template and its echoed operand. It now decomposes the pattern — dropping only the fragments the:pads could supply and requiring a non-empty core in the script — so shapes with no such fragment stay absolute and a builtin format string that spells a shape itself still fails.Subscript text is deliberately left verbatim. It is handed to arithmetic or associative-key expansion, which resolve quoting themselves, and
try_parse_assignmentalso recovers a marker-bearing subscript from raw source; escaping it in the lexer alone makes assignment and lookup disagree. That pre-existing divergence from bash is unchanged, pinned by a test, and recorded as aTODO.2.
fix(deps)— capmarkkitbelow 0.3.2 to hold the Rust 1.96 consumer floor. This is unrelated to the parser work and is here only because it blocked this PR's CI; see the note under Risk.Why
Nightly
Fuzz Testinghas been red since 2026-11-24. The 2026-11-26 run failed three jobs:tomlq_fuzztarget/debug/deps/\x1ffromtarget/debug/<1f><1f><1f>deps/, so the diagnostic quoted back a host path the script never spelledawk_fuzz{ code:awk: cmd. line:1: {program}spells it from the template's:plus the programprintf_fuzz{ code:printf: {arg}: invalid numberspells it the same wayThe earlier red runs (11-24, 11-25) were the literal-shape class already fixed, plus a tomlq char-boundary panic fixed by #3016, so nothing in the current red is left uncovered.
The lexer half is a user-visible bash-compatibility bug in its own right, independent of fuzzing.
Before / After
A new bash-oracle test compares bashkit against real host bash for both bytes across 20 quoting contexts per byte — single/double/unquoted, concatenated segments, backslash escapes, ANSI-C quoting, variables,
${...}operands, command substitution, globs, array elements, here-documents (quoted and unquoted),[[ ]],case, and IFS splitting. All agree byte for byte.All three crash units are replayed in
tests/fuzz_crash_regressions.rsand failed before the fix.For the dependency cap,
scripts/check-msrv-consumer.py --profile allon Rust 1.96.0:Risk
matches!on each literal source character, taking the existing NUL-sentinel path that single quotes already used.just testis green (7614 tests) andcargo clippy --all-targets -- -D warningsis clean.Note on the
Rust 1.96 consumer (all)failureThat job's first failure here was not from this diff.
markkit0.3.2 was published today at 04:57 UTC (0.3.3 at 05:57) and moved frommail-parser ^0.11to^1.0; every mail-parser 1.x declaresrust-version = 1.98. Themsrvjob resolves a fresh consumer while ignoring this repository's Cargo.lock, so it picked markkit 0.3.3 → mail-parser 1.0.2 and breached the floor. The same job passed on main at 03:06 UTC, and the failure reproduces on an unmodified checkout.Since main's next run would hit the same wall, the fix is carried here: cap markkit and markkit-cli below 0.3.2, in lockstep because markkit-cli 0.3.3 requires
markkit ^0.3.3.Cargo.lockis unchanged (it already pinned 0.3.1), so only fresh resolution is constrained and the dependency graph the audit andcargo denysee is identical. markkit is optional and off by default, which is why only theallprofile was affected.Maintainer call: the alternative is raising the consumer floor to 1.98, which drops Rust 1.96/1.97 consumers. AGENTS.md says to preserve that floor, so this PR takes the conservative option. Happy to swap it for a floor bump instead, and ideally this would be its own PR — it is bundled here only because this session may push to a single branch.
Also note
just pre-prfailscheck-changelogon an unrelated pre-existing issue ([0.22.0] unexpected subsection '### Breaking Changes'), reproducible on unmodifiedorigin/main. Left alone.Checklist
Generated by Claude Code