Avoid panic when truncating non-ASCII Strato responses for logging - #49
Open
huxint wants to merge 1 commit into
Open
Avoid panic when truncating non-ASCII Strato responses for logging#49huxint wants to merge 1 commit into
huxint wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The parse-error paths in
fetch_following_listandfetch_user_metadatabuild a log preview with&text[..text.len().min(300)]. Indexing astrat 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:157and: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_metadatacurrently has no caller, andfetch_following_listis 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 onlystdstrmethods andrustfmtparses the file cleanly.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.