Skip to content

fix(extract): guard remember fast-path against UTF-8 char-boundary panic#641

Closed
e11734937-beep wants to merge 1 commit into
GeniePod:mainfrom
e11734937-beep:fix-extract-utf8-panic
Closed

fix(extract): guard remember fast-path against UTF-8 char-boundary panic#641
e11734937-beep wants to merge 1 commit into
GeniePod:mainfrom
e11734937-beep:fix-extract-utf8-panic

Conversation

@e11734937-beep

Copy link
Copy Markdown
Contributor

Fixes #634.

extract_facts sliced trimmed[..8] (and extract_remember sliced text[..PREFIX.len()]) behind only a byte-length check, so any utterance whose 8th byte fell inside a multi-byte UTF-8 character panicked with "byte index 8 is not a char boundary".

Three sites had this pattern:

  • the early-return !needs_extract_facts_lower fast-path,
  • the main extract_facts "remember" branch,
  • the extract_remember prefix check.

Each now uses str::get(..n), which returns None when the index is out of range or not a char boundary — so non-ASCII input simply doesn't match the fast-path instead of panicking. ASCII "remember" behaviour is unchanged.

Regression tests added:

  • non_ascii_input_does_not_panic — CJK / mixed / emoji inputs whose interior byte 8 previously panicked no longer do, and don't spuriously match.
  • remember_still_matches_with_non_ascii_payload — a genuine Remember 日本語 … request is still captured with its payload preserved.

extract_facts sliced trimmed[..8] (and extract_remember sliced
text[..PREFIX.len()]) behind only a byte-length check, so an utterance
whose 8th byte fell inside a multi-byte UTF-8 char panicked (byte index
8 is not a char boundary). Use str::get(..n), which returns None instead
of panicking on a non-char-boundary, so non-ASCII input simply does not
match the fast-path. Adds a regression test with CJK/emoji inputs whose
byte 8 is interior.

Closes GeniePod#634
@github-actions github-actions Bot added the bug Something isn't working label Jul 6, 2026

@matedev01 matedev01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same fix as #635 (already approved), which extracts a reusable starts_with_ascii_ci helper. Closing as duplicate — please coordinate on #635.

@matedev01 matedev01 closed this Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] extract_facts panics on non-ASCII input (UTF-8 char-boundary slice in the "remember" fast-path)

2 participants