rfc822: prevent infinite loop on partial folded header lines #3
Labels
No labels
nagonag
nagonag/ignore
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
heiko/mailseal#3
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
internal/rfc822/parser.gocomputes the next newline position as:When
p.offset > 0andbytes.Indexreturns-1, adding the offset can produce a nonnegativei. The “incomplete input” branch is skipped. For a folded header whose continuation bytes have arrived but whose next newline has not, the split function can repeatedly reuse the same offset and spin indefinitely.This parser processes attacker-controlled email in the intended MTA deployment, so the bug is an availability/CPU-denial-of-service risk.
The unconditional
log.Println("XXX:", p.offset)also leaks parser internals to stderr whenever this state occurs.Checklist: #18 (unsafe integer/sentinel arithmetic).
Proposed fix
Check the relative index before adding the offset:
Re-evaluate offset reset semantics for EOF and malformed headers, and remove the unconditional diagnostic.
Acceptance criteria
Parse/scanLineswith chunked readers.go test -race -shuffle=on ./...passes.Reviewed against
948b7a9onmaster(Go 1.26.2).The partial folded-header spin is fixed, race-safe regression coverage is present, and the parser fuzz target with seeds is complete.
Closing commit:
403c6ef92db2