Skip to content

Avoid panic when truncating non-ASCII Strato responses for logging - #49

Open
huxint wants to merge 1 commit into
xai-org:mainfrom
huxint:fix/thunder-utf8-log-truncation
Open

Avoid panic when truncating non-ASCII Strato responses for logging#49
huxint wants to merge 1 commit into
xai-org:mainfrom
huxint:fix/thunder-utf8-log-truncation

Conversation

@huxint

@huxint huxint commented Aug 14, 2026

Copy link
Copy Markdown

Summary

The parse-error paths in fetch_following_list and fetch_user_metadata build a log preview with &text[..text.len().min(300)]. Indexing a str at a fixed byte offset panics if the offset falls inside a multi-byte UTF-8 character, so a malformed-but-non-ASCII response crashes the task from inside its own error-logging path.

Root cause

thunder/strato_client.rs:157 and :227. Response bodies routinely contain non-ASCII data (user display names), so byte 300 landing mid-character is realistic whenever the parse-error branch is reached.

Severity is limited in this snapshot: fetch_user_metadata currently has no caller, and fetch_following_list is only reached for debug requests with an empty following list — so this is a hardening fix for code that is more exposed wherever these clients are used elsewhere.

Fix

Add preview_for_log, which truncates at the nearest char boundary at or below 300 bytes. Output is unchanged for ASCII and short responses.

Verification

  • thunder/ ships no Cargo manifest, so the crate cannot be compiled from this snapshot; the helper uses only std str methods and rustfmt parses the file cleanly.
  • I verified the helper as a standalone test binary: the original expression panics on a 299-ASCII-bytes-plus-emoji input (via catch_unwind); the fixed version backs up to byte 299, matches the original output on ASCII, short, and exactly-300-byte inputs, and never panics across all emoji straddle offsets.

The parse-error paths in fetch_following_list and fetch_user_metadata
build a log preview with &text[..text.len().min(300)]. Indexing a str by
a fixed byte offset panics if that offset falls inside a multi-byte
UTF-8 character, and these response bodies routinely contain non-ASCII
data (user display names). A malformed-but-non-ASCII response would
crash the task from inside its own error-logging path.

Truncate at the nearest char boundary at or below 300 bytes instead.
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