Fix crash in parsing received hops chain#37
Open
ulidtko wants to merge 2 commits into
Open
Conversation
Example crash:
> Traceback (most recent call last):
> File "/tmp/decode-spam-headers.py", line 6925, in <module>
> main(sys.argv)
> ~~~~^^^^^^^^^^
> File "/tmp/decode-spam-headers.py", line 6905, in main
> out = an.parse(text)
> File "/tmp/decode-spam-headers.py", line 2285, in parse
> self.results[testName] = testFunc()
> ~~~~~~~~^^
> File "/tmp/decode-spam-headers.py", line 5209, in testReceived
> vers = SMTPHeadersAnalysis.parseExchangeVersion(obj['ver'])
> File "/tmp/decode-spam-headers.py", line 2107, in parseExchangeVersion
> lookupparsed = packaging.version.parse(lookup)
> File "/Users/maksym.ivanov/Library/Python/3.14/lib/python/site-packages/packaging/version.py", line 56, in parse
> return Version(version)
> File "/Users/maksym.ivanov/Library/Python/3.14/lib/python/site-packages/packaging/version.py", line 202, in __init__
> raise InvalidVersion(f"Invalid version: {version!r}")
> packaging.version.InvalidVersion: Invalid version: 'ffacd0b85a97d-42f7cbd8c20si11690432f8f.269.2025.12.09.06.21.40'
In Recieved: headers, value under `id` is not necessarily formatted as a version string.
ulidtko
added a commit
to ulidtko/decode-spam-headers
that referenced
this pull request
Dec 16, 2025
Cherry-pick of open PR mgeeky#37 (squashed)
ulidtko
commented
Dec 16, 2025
Comment on lines
+2109
to
+2111
| try: | ||
| lookupparsed = packaging.version.parse(lookup) | ||
| except packaging.version.InvalidVersion: |
Author
There was a problem hiding this comment.
This is the crux of the fix. 👀 Everything else -- drive-by cleanups / refactors
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.
Stumbled into a case where
packaging.version.parsegets fed with"ffacd0b85a97d-42f7cbd8c20si11690432f8f.269.2025.12.09.06.21.40"and so crashes withInvalidVersionexception.That ID is clearly not a version string. I also don't see why it ever would be. 🤔
-- https://www.rfc-editor.org/rfc/rfc5321#section-4.4
The
ID clauseinReceived:header -- is supposed to be mta-local "message id"; it's not intended to contain versions. In practice, I see it taking values such as:ls17csp2524806jab,6a1803df08f44-888284b1477si197598466d6.457.2025.12.09.06.21.46,A0F173EFD3,ffacd0b85a97d-42f89f48092mr11828940f8f.31.1765290101044,No idea why the code hopes to find a version string in there; I just stubbed it out so that a None is returned instead of exception, and the report then actually shows the
receivedserver hops chain.