UTF-8 string slicing panic with Korean text in lolhtml text encoder

Resolved 💬 3 comments Opened Jan 3, 2026 by jemulpoclub Closed Jan 6, 2026

Bug Description

Claude Code panics when processing Korean text due to incorrect UTF-8 string slicing in the lolhtml text encoder.

Error Message

thread '<unnamed>' panicked at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/str/mod.rs:833:21:
byte index 5 is not a char boundary; it is inside '르' (bytes 3..6) of `포르 1`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5, aborting
Aborted (core dumped)

Root Cause Analysis

The bug is in the lolhtml library's text encoder, which slices UTF-8 strings at byte indices instead of character boundaries.

Affected files (from binary analysis):

  • vendor/lolhtml/src/rewritable_units/text_encoder.rs
  • src/text_chunk.rs

UTF-8 breakdown of 포르 1:
| Character | Bytes |
|-----------|-------|
| 포 | 0-2 (3 bytes) |
| 르 | 3-5 (3 bytes) |
| (space) | 6 (1 byte) |
| 1 | 7 (1 byte) |

When the code attempts to slice at byte index 5, it falls inside the Korean character (which spans bytes 3-5), causing Rust's string boundary validation to panic.

Environment

  • Claude Code Version: 2.0.76
  • OS: Rocky Linux 9 (Linux 5.14.0-605.el9.x86_64)
  • Platform: linux x86_64

Impact

  • Crashes Claude Code completely with core dump
  • Affects Korean text and likely other multi-byte Unicode (CJK, Emoji, etc.)
  • Occurs during text chunk processing/truncation

Suggested Fix

Use character-aware string slicing instead of byte-based slicing:

// Instead of:
&text[..n]  // Panics if n is not a char boundary

// Use:
text.char_indices()
    .take_while(|(i, _)| *i < n)
    .map(|(_, c)| c)
    .collect::<String>()

// Or:
text.chars().take(n).collect::<String>()

Steps to Reproduce

  1. Use Claude Code in a context with Korean text
  2. Trigger text processing that causes chunking/truncation near Korean characters
  3. Observe panic and core dump

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗