aws / aws/amazon-q-developer-cli
panic: byte index out of bounds in chat response rendering when response contains triple backticks
Nessuno ha ancora preso questa issue.
- Lingua principale
- Rust
- Stelle
- 2k
- Fork
- 439
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Bug Report
Version: kiro-cli 1.25.1
OS: Debian GNU/Linux 12 (bookworm), kernel 6.1.0-44-amd64, x86_64
Install method: Official install script from kiro.dev (curl)
Binary location: /home/dev/.local/bin/kiro-cli
Description
The application panics with a byte index out of bounds error when the AI response contains triple backticks (```````) in the rendered output.
Steps to Reproduce
- Start a chat session:
kiro-cli chat - Ask a question that causes the AI to respond with a message containing triple backticks (e.g., a code block or a message referencing backtick syntax)
- The application crashes mid-response
Panic Output
The application panicked (crashed).
Message: byte index 536 is out of bounds of `...`[...]
Location: crates/chat-cli/src/cli/chat/mod.rs:3849
Root Cause Analysis
In crates/chat-cli/src/cli/chat/mod.rs, the response rendering loop uses a byte offset to track parsing progress:
let input = Partial::new(&buf[offset..]);
// ...
offset += parsed.offset_from(&input);
parsed.offset_from(&input) returns a byte count relative to the input slice. This is accumulated into offset, which is used as a byte index into buf. When buf contains multi-byte UTF-8 characters (e.g., non-ASCII text, emoji, or characters adjacent to triple backticks), the accumulated offset can land in the middle of a multi-byte character boundary, causing the panic on the next iteration when &buf[offset..] is evaluated.
Suggested Fix
Validate that offset falls on a valid UTF-8 character boundary before slicing, or use buf.get(offset..) which returns None instead of panicking:
// Instead of:
let input = Partial::new(&buf[offset..]);
// Use:
let Some(slice) = buf.get(offset..) else { break };
let input = Partial::new(slice);
Alternatively, ensure offset is always advanced using ceil_char_boundary or equivalent to stay on valid UTF-8 boundaries.
Additional Context
This panic is reproducible when the AI response includes triple backticks in its text content (not just code blocks), particularly when the surrounding text contains non-ASCII characters.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in crates/chat-cli/src/cli/chat/mod.rs, intorno al loop di rendering della risposta alla riga 3849, e verifica come viene usato offset con Partial e l’input slice. Riproduci il problema con kiro-cli chat usando una risposta contenente triple backticks insieme a testo non ASCII. Il lavoro è completato quando la risposta viene visualizzata senza un panic relativo ai confini dei byte.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust
- Ambito
- cli
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 72/100