Skip to content

fix: two UTF-8 slicing panics (harmony scan windows, title quotes) - #484

Merged
mrnasil merged 4 commits into
mainfrom
fix/core-harmony-char-boundary
Nov 25, 2026
Merged

mrnasil merged 4 commits into
mainfrom
fix/core-harmony-char-boundary

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 25, 2026

Copy link
Copy Markdown
Member

Two crashes found in the code audit, both from slicing a &str by byte offset.

1. Harmony leak scan (core/src/harmony.rs)

glitch_near and fake_result_after look 80 bytes back and 240 bytes ahead of an unquoted to=functions. marker. They slice with raw byte offsets, so with Turkish, CJK or emoji text near the marker the edge lands inside a character and the agent turn panics. The text can be the model's visible text, its thinking, or the arguments of an edit to such a file.

Fix: round the edges outward with floor_char_boundary / ceil_char_boundary, which the repo already uses (MSRV 1.91).

Test: windows_around_a_marker_respect_char_boundaries uses 2-, 3- and 4-byte characters at four shifts. It panics at harmony.rs:187 on the old code and passes now.

2. sanitize_title (session/src/title.rs)

s[1..s.len() - 1] assumed one-byte quotes:

  • A curly-quoted title from the title model (“Fix login bug”, 3 bytes per quote) panicked.
  • A lone " (for example /rename ") gave s[1..0] and panicked.

Fix: strip_prefix(open) then strip_suffix(close), per quote pair.

Tests: cases for curly quotes, a lone ", and ''.

core and session lib tests, clippy, fmt and budgets pass.

🤖 Generated with Claude Code

- harmony: `glitch_near` / `fake_result_after` sliced an 80-byte
  look-back and a 240-byte look-ahead around an unquoted
  `to=functions.` marker by byte. With Turkish, CJK or emoji text near
  the marker (model text, thinking, or an `edit` of such a file), the
  edge fell inside a character and the agent turn panicked. The edges
  now round outward to a char boundary.
- sanitize_title: `s[1..len-1]` panicked on a curly-quoted title
  (`“…”`, three bytes each) from the title model, and on a lone `"`
  (a user rename). Quotes are now stripped with strip_prefix/suffix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mrnasil
mrnasil enabled auto-merge (squash) November 25, 2026 13:28
@mrnasil
mrnasil merged commit ff10492 into main Nov 25, 2026
7 checks passed
@mrnasil
mrnasil deleted the fix/core-harmony-char-boundary branch November 25, 2026 20:04
@mrnasil mrnasil mentioned this pull request Nov 26, 2026
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.

1 participant