Skip to content

fix(reconstruct): bound diagnostic text at a valid UTF-8 boundary - #1056

Open
AmirF194 wants to merge 1 commit into
tokencanopy:mainfrom
AmirF194:fix/reconstruct-bounded-utf8-boundary
Open

AmirF194 wants to merge 1 commit into
tokencanopy:mainfrom
AmirF194:fix/reconstruct-bounded-utf8-boundary

Conversation

@AmirF194

Copy link
Copy Markdown
Contributor

Summary

Fixes #1055. bounded() sliced diagnostic text at a raw byte offset, so a multi-byte rune landing on the 2048-byte cap got cut mid-rune. SafeDiagnostic() already does this correctly for a different call site (model.go); this routes bounded() through it instead of keeping a second, slightly wrong copy of the same logic.

Added a test that feeds a RecipientSnapshot.Detail sized so the cap always splits the last rune, through the real Reconstruct() path. It fails on main: the returned smtp_detail is invalid UTF-8, and after the JSON round-trip in cloneTransition it's actually longer than the cap it's meant to enforce (U+FFFD substitution grows the trailing bytes).

Client surface checklist

No API or client surface change, internal-only fix.

Test plan

  • go test ./internal/messagelifecycle/...: the new test is red without this change, green with it. Rest of the package suite is unaffected.
  • make fmt-check, go build ./..., go vet ./internal/messagelifecycle/... clean.

bounded() sliced smtp_detail/failure_reason/failure_code/review_resolution
at a raw byte offset with no rune-boundary check, unlike its sibling
SafeDiagnostic(). Route it through SafeDiagnostic() so both share the
same truncation rule.

Fixes tokencanopy#1055
@AmirF194
AmirF194 requested a review from jiashuoz as a code owner September 27, 2026 16:14
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.

bounded() truncates SMTP diagnostic text at a raw byte offset, splitting UTF-8 runes

1 participant