Skip to content

Fix/quadratic backtracking in email scan - #91

Open
moussetf wants to merge 5 commits into
GOVCERT-LU:masterfrom
moussetf:fix/quadratic-backtracking-in-email-scan
Open

Fix/quadratic backtracking in email scan#91
moussetf wants to merge 5 commits into
GOVCERT-LU:masterfrom
moussetf:fix/quadratic-backtracking-in-email-scan

Conversation

@moussetf

@moussetf moussetf commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

This change improves the asymptotic performance when parsing an e-mail with a very long Receive: header from quadratic to linear.

The constant factor is still pretty large; for example, parsing a Receive header of 1MB still takes ~2.5s on my machine. OTH before this change, it would have taken multiple minutes.

This is achieved by modifying the regex used to parse e-mail addresses to impose a maximum length of 128 characters on the local part of the e-mail address (the part before the @-sign). Legal e-mail addresses should not have local parts with more than 64 characters.

Frank Mousset added 4 commits August 25, 2026 14:45
This change limits the length of the local part in the email regex to 64
characters (the maximum allowed). This solves the problem that
`email_regex.findall(string)` takes time that grows quadratically with
the length of the string.
@moussetf
moussetf requested a review from sim0nx September 1, 2026 07:57
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.

2 participants