Fix TypeError when passing INFINITY to VerifyingKey.from_public_point()#378
Open
gaoflow wants to merge 1 commit into
Open
Fix TypeError when passing INFINITY to VerifyingKey.from_public_point()#378gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
Passing `ellipticcurve.INFINITY` to `VerifyingKey.from_public_point()`
raised a `TypeError` ('<=' not supported between instances of 'int' and
'NoneType') instead of the documented `MalformedPointError`.
The root cause: `INFINITY.x()` returns `None`, and `Public_key.__init__`
compared `0 <= point.x() < p` before checking for the point at infinity.
`PointJacobi.from_affine(INFINITY)` also produced a PointJacobi with
`x=None`, so the TypeError occurred inside `Public_key.__init__` rather
than being caught and re-raised as `MalformedPointError`.
Fix by adding an explicit INFINITY guard in both `Public_key.__init__`
(raises `InvalidPointError`) and `VerifyingKey.from_public_point`
(raises `MalformedPointError`) before any coordinate access.
Fixes tlsfuzzer#341.
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.
Problem
Passing
ellipticcurve.INFINITYtoVerifyingKey.from_public_point()raises aTypeErrorinstead of the documentedMalformedPointError:Reported in #341.
Root cause
INFINITYisPoint(None, None, None), soINFINITY.x()returnsNone.Public_key.__init__evaluated0 <= point.x() < pbefore checking for the point at infinity, producing aTypeError. Additionally,PointJacobi.from_affine(INFINITY)wraps INFINITY into aPointJacobiwithx=None, so the TypeError happened before theexcept ecdsa.InvalidPointErrorhandler infrom_public_pointcould convert it toMalformedPointError.Fix
Two guard lines — one in each layer:
ecdsa.py–Public_key.__init__: checkpoint == ellipticcurve.INFINITYand raiseInvalidPointErrorbefore any coordinate access.keys.py–VerifyingKey.from_public_point: checkpoint == ellipticcurve.INFINITYand raiseMalformedPointErrorbefore thefrom_affineconversion.A regression test is included.
This pull request was prepared with the assistance of AI, under my direction and review.