Skip to content

fix: UTF-8 string truncation panic with multi-byte characters#48

Merged
XuPeng-SH merged 2 commits intomatrixorigin:mainfrom
XuPeng-SH:fix_bugs2
Mar 18, 2026
Merged

fix: UTF-8 string truncation panic with multi-byte characters#48
XuPeng-SH merged 2 commits intomatrixorigin:mainfrom
XuPeng-SH:fix_bugs2

Conversation

@XuPeng-SH
Copy link
Collaborator

What type of PR is this?

  • feat (new feature)
  • fix (bug fix)
  • docs (documentation)
  • style (formatting, no code change)
  • refactor (code change that neither fixes a bug nor adds a feature)
  • perf (performance improvement)
  • test (adding or updating tests)
  • chore (maintenance, tooling)
  • build / ci (build or CI changes)

Which issue(s) this PR fixes

Fixes #

What this PR does / why we need it

Fix panic when truncating strings containing multi-byte UTF-8 characters (e.g., Chinese punctuation). The code was slicing at byte boundaries that could land inside a character.

  • Extract truncate_utf8() helper to memoria-core for reuse
  • Fix 3 locations: sessions.rs (500 bytes), tools.rs (2000 bytes), service.rs (2000 bytes)
  • Add CatchPanicLayer to return proper JSON error on panics
  • Add unit tests for the truncation logic

@XuPeng-SH XuPeng-SH merged commit f774499 into matrixorigin:main Mar 18, 2026
4 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.

1 participant