Repository navigation
replace raw header errors with typed MalformedHeaderError with kind and offset - #17
Merged
Merged
Conversation
Replace the raw-string "malformed MIME header" errors with *MalformedHeaderError, carrying a Kind (initial line, line, key) and the byte Offset from the start of the header block. The key error previously reported no position at all. readLineSlice now counts consumed bytes so offsets are exact for both CRLF and LF input. Adds IsMalformedHeader, and switches both Is* helpers to errors.AsType. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Multipart recovery tests do not verify both wrapped error types via errors.As or confirm that offsets reset per part, including malformed lines after valid LF- and CRLF-terminated headers.
1 open issue
What changed in this PR
This PR adds typed MIME header errors so callers can identify malformed headers and their byte offsets without exposing offending header text.
Changes:
- Introduces
MalformedHeaderError, error kinds, andIsMalformedHeader. - Tracks consumed bytes for LF and CRLF input, including part-relative offsets in multipart headers.
- Adds tests for malformed initial lines, missing colons, and invalid keys.
| File | Description |
|---|---|
textproto/multipart.go |
Tracks part-relative offsets and updates error detection to errors.AsType. |
textproto/header.go |
Defines typed errors and tracks byte offsets during header parsing. |
textproto/header_test.go |
Tests malformed-header kinds and offsets for LF and CRLF input. |
Review effort: Balanced
Check that NextPart's MalformedPartHeaderError wraps a MalformedHeaderError and that the offset restarts at each part's header, for both LF and CRLF line endings. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
thunderkatz
marked this pull request as ready for review
November 5, 2026 14:25
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
https://app.notion.com/p/sublimesecurity/Enhance-header-repair-for-positional-issues-and-rejoins-40d04655fc9d81ea8193ca14d13b901a
malformed MIME header ...errors (initial line, line without colon, invalid key) with*MalformedHeaderError{Kind, Offset}.Offsetis the byte offset from the start of the header block of the offending line (or key). The key error previously carried no position.readLineSlicenow counts consumed bytes, so offsets are exact for CRLF and LF input. For part headers the offset is relative to the start of that part's header.IsMalformedHeader;MalformedPartHeaderErrorstill wraps the new error, soerrors.Asworks on either. BothIs*helpers useerrors.AsType.Test plan
go test ./...TestReadHeader_malformedHeaderErrorcovers each kind and offsets (LF and CRLF)🤖 Generated with Claude Code