Repository navigation
fix(mermaid-text): UTF-8 safety — byte offsets used as char offsets (#29) - #31
Merged
Merged
Conversation
…ut (#29) Two reported defects + two found while auditing the sibling arrow consumers, all the same byte-vs-char class: - Bug 1 (panic): strip_keyword_prefix sliced at keyword.len() (a byte index) without a char-boundary check, so a non-ASCII keyword-prefixed line (e.g. `loop до готовности`) panicked when that byte landed inside a multi-byte char. Now uses str::get, rejecting non-boundary slices instead of crashing. Preserves the ASCII-fast path. - Bug 2 (silent corruption): try_consume_pipe_label returned a byte length that the char-indexed tokenizer added to its cursor, over-advancing by byte_len-char_len and eating part of the next node token (leaking its `[` bracket into the label). Now returns a char count. - Bug 2b: same defect in try_consume_inline_compact_arrow (`-.label.->` / `==label==>`). - Bug 2c (not in the report): try_consume_inline_quoted_arrow measured the consumed slice — which includes the multi-byte quoted label — with s.len()-tail.len() (bytes). Now counts chars. 6 new regression tests in tests/utf8_multibyte.rs, each confirmed to fail before the fix. Full workspace suite green, fmt/clippy clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
) The reporter predicted the byte-vs-char pattern recurs across the other parsers. A full sweep (docs/audit-mermaid-text-utf8-2026-07-15.md) confirmed two more real sites; git_graph was a false positive (verified its slices only land on ASCII boundaries). - sequence.rs parse_participant_decl: searched for " as " in a to_lowercase() copy, then applied that byte offset to the ORIGINAL string. Case-folding that changes byte length (e.g. `İ` U+0130 -> 3-byte `i̇`) desynced the offset and panicked/mis-split the id/alias. Now scans the original bytes for the ASCII " as " separator (always a char boundary), dropping the lowercased-copy allocation entirely. - gantt / timeline / journey each carried their OWN copy of the keyword-strip helper still slicing at `line[..keyword.len()]` — the copies the common.rs fix never reached. Deleted all three and routed them to the now-canonical common::strip_keyword_prefix, removing the duplication that caused the miss. 4 new regression tests (case-fold alias + one per parser), each confirmed to panic before the fix. Full workspace suite green, fmt/clippy clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Ships the #29 UTF-8 fixes: mermaid-text 0.56.1 (byte-vs-char panics and label corruption on non-ASCII diagram text) and bumps the app to depend on it, app version 1.34.74. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…5/0206 ignore) Four advisories landed on master's dependency tree since #26 and turn the cargo-deny gate red (unrelated to the #29 fix; folded in here to unblock this PR): - RUSTSEC-2026-0204 (crossbeam-epoch invalid-pointer deref): upgraded 0.9.18 -> 0.9.20 via `cargo update` (semver-compatible, real fix). - RUSTSEC-2026-0206 (rustybuzz unmaintained): documented ignore — same internally-generated-SVG stack as the ttf-parser ignore; no safe upgrade per the advisory. - RUSTSEC-2026-0194 / 0195 (quick-xml < 0.41 DoS): documented ignore — reached only via syntect -> plist parsing our BUNDLED theme files (never attacker-controlled), and the 0.41 fix is a semver-breaking bump that `plist` pins away from. No upgrade path from our side. Each ignore cites its upstream blocker for the quarterly re-audit. cargo deny check green. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…in_formatting) CI's stable toolchain moved 1.95 -> 1.97, whose clippy flags two pre-existing patterns as -D warnings errors (unrelated to #29, surfaced by the bump; blocks this PR's Clippy job): - requirement_diagram.rs: collapse an if-let/else-return into `?`. - checklinks/mod.rs: drop redundant `&` in four `format!` args. Both are mechanical, behaviour-preserving. clippy --all-targets -D warnings and the full suite are green on 1.97. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The CI `audit` job (continue-on-error, non-blocking) went perpetually red on the same advisories deny.toml already handles, because cargo-audit reads its OWN config (.cargo/audit.toml), not deny.toml. A permanently-red audit masks new advisories, so mirror the justified ignore set here to keep the signal meaningful: - 0192/0206 (ttf-parser/rustybuzz unmaintained), 0141/0320 (syntect deps) - 0194/0195 (quick-xml DoS — bundled-theme-only, no upgrade path) deny.toml stays the source of truth; a header note asks to keep the two in sync. New advisories (currently memmap2 0186, rand 0097, both warning-severity) stay visible and non-blocking by design. `cargo audit` exits 0 locally. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
leboiko
added a commit
that referenced
this pull request
Jul 16, 2026
…#30) @vshylov opened PR #30 with the correct fix before this maintainer wrote and merged the superseding #31 without checking for an existing PR. The shipped mermaid-text 0.56.1 fix is substantially their work; correct the CHANGELOG credit from "reported by" to "reported and originally fixed by", naming PR #30. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
7 of 9 tasks
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.
Fixes #29. Reported by @vshylov with an excellent, reproducible write-up.
The bug class
mermaid-textused byte offsets where character offsets were expected, producing two failure modes on non-ASCII (e.g. Cyrillic) diagram text:&strat a byte index that falls inside a multi-byte char.Vec<char>, over-advancing on multi-byte labels and eating the next token.What's fixed (6 sites)
Reported (flowchart + common):
common::strip_keyword_prefixloop до готовностиstr::getinstead ofline[..len]flowchart::try_consume_pipe_labelflowchart::try_consume_inline_compact_arrow-.да.->corrupts next nodeflowchart::try_consume_inline_quoted_arrow-. "да" .->corrupts next node (not in report)s.len()-tail.len()Found by a full parser audit (
docs/audit-mermaid-text-utf8-2026-07-15.md), confirming the reporter's "broader note":sequence::parse_participant_declparticipant İd as …as, not ato_lowercase()copygantt/timeline/journeykeyword-stripcommon::strip_keyword_prefix(removing the copy-paste that made the central fix miss them)git_graphwas flagged by the audit but verified clean (its slices only land on ASCII boundaries) — not touched.Tests
10 new regression tests in
crates/mermaid-text/tests/utf8_multibyte.rs, each confirmed to panic/corrupt before its fix and pass after. Assertions are strong (no bracket may leak; all labels must survive; alias must split correctly) — a no-op fix cannot satisfy them.Also in this PR
mermaid-text0.56.0 → 0.56.1, appmarkdown-tui-explorer1.34.73 → 1.34.74 (depends on the fixed crate). Both CHANGELOGs updated.crossbeam-epoch0.9.18 → 0.9.20 (fixes RUSTSEC-2026-0204), documented-ignore forrustybuzz(0206) andquick-xmlDoS (0194/0195) — both transitive with no upgrade path and non-attacker-controlled reach. Each ignore cites its upstream blocker.Verification
cargo build,cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo test --workspace(1539 passing), andcargo deny check— all green locally.Answering @vshylov's separate width question in an issue comment (it's a soft hint today, not a hard budget — sequence diagrams deliberately ignore
max_width).🤖 Generated with Claude Code