Skip to content

Fix hang on long MIME boundaries - #151

Merged
staktrace merged 1 commit into
staktrace:masterfrom
staktrace-bot:fix-quadratic-boundary-search
Nov 14, 2026
Merged

staktrace merged 1 commit into
staktrace:masterfrom
staktrace-bot:fix-quadratic-boundary-search

Conversation

@staktrace-bot

Copy link
Copy Markdown
Collaborator

find_from_u8_line_prefix searched for the boundary and then checked for a preceding newline, restarting one byte later after each mid-line miss. A long boundary with similar mid-line text made this quadratic and effectively hang.

This walks line starts with find_byte so the search is linear in the message size. If the key itself contains a newline (which a MIME boundary cannot), it falls back to the previous search to preserve behaviour. A regression test uses the reproducer from the issue.

Fixes #148

find_from_u8_line_prefix searched for the boundary and then checked
for a preceding newline, restarting one byte later after each mid-line
miss. A long boundary with similar mid-line text made this quadratic
and effectively hang (issue staktrace#148).

Search only at line starts so the cost is linear in the message size.
If the key itself contains a newline, fall back to the previous
search to preserve behaviour. Add a regression test using the issue's
reproducer.
@staktrace
staktrace merged commit 2a1e9a6 into staktrace:master Nov 14, 2026
5 checks passed
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.

Search for MIME boundary may be slow if the boundary is long

2 participants