Skip to content

fix(ink): no panic on a character across byte 4096 of an SVG (#126) - #145

Merged
DWAA1660 merged 2 commits into
AlienTechSoftware:mainfrom
DWAA1660:fix/ink-detect-char-boundary
Nov 12, 2026
Merged

DWAA1660 merged 2 commits into
AlienTechSoftware:mainfrom
DWAA1660:fix/ink-detect-char-boundary

Conversation

@DWAA1660

Copy link
Copy Markdown
Collaborator

What and why

Fixes #126. notecraft_ink::svg::is_ink took &text[..text.len().min(4096)], which panics when a multibyte character crosses byte 4096. page::ink_files runs it over the lossily-decoded first 4096 bytes of every SVG beside a page when the page opens. An ordinary picture with, say, an é in a long comment therefore crashed the window. With a lossy head, the string ends in a 3-byte U+FFFD that crosses the cut as well.

The head is now &text[..text.floor_char_boundary(4096)] (str::floor_char_boundary is stable well below the workspace's rust-version = 1.95). Detection still reads only the head, as before.

How it was checked

  • New svg::tests::a_character_across_byte_4096_is_not_split: the issue's SVG, a lossy 4096-byte head of it ending in U+FFFD, and a real ink file with long multibyte text after its tag (still detected)
  • New page::tests::a_character_across_the_head_of_an_svg_does_not_stop_the_page_opening: the issue's SVG beside a real page. ink_files returns nothing and the page loads.
  • cargo test -p notecraft-ink -p notecraft-store: pass
  • cargo fmt --all -- --check, cargo clippy -p notecraft-ink -p notecraft-store --all-targets -- -D warnings: clean

🤖 Generated with Claude Code

DWAA1660 and others added 2 commits November 12, 2026 10:46
`svg::is_ink` looked at the first 4096 bytes with a plain slice, which
panicked when a character crossed byte 4096. The page scan reads such a
head from every SVG beside a page, so an ordinary picture with a long
comment took the window down while its page opened (AlienTechSoftware#126). The head is
now cut with `floor_char_boundary`.

Fixes AlienTechSoftware#126

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DWAA1660
DWAA1660 merged commit 477834c into AlienTechSoftware:main Nov 12, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] A Unicode character across byte 4096 in an ordinary SVG crashes ink detection

1 participant