Repository navigation
Reject BIT STRINGs whose length exceeds the buffer - #393
Open
0xrichardlu wants to merge 1 commit into
Open
0xrichardlu wants to merge 1 commit into
0xrichardlu wants to merge 1 commit into
Conversation
remove_bitstring() sliced the body without checking the declared length, so a truncated BIT STRING was silently accepted (VerifyingKey.from_der() returned the key) and b'\x03\x01' raised IndexError instead of UnexpectedDER. The other remove_* helpers already check this.
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.
remove_bitstring()reads the declared length and then slicesstring[1 + llen : 1 + llen + length]without checking that the buffer is that long.remove_sequence,remove_octet_string,remove_integer,remove_constructedand the rest all raiseUnexpectedDER("Length longer than the provided buffer")in this case.remove_bitstringdidn't.As a result, a SubjectPublicKeyInfo whose BIT STRING claims more bytes than are present is accepted:
cryptography'sload_der_public_keyrejects the same bytes ("short data"). Separately,remove_bitstring(b"\x03\x01", 0)raisedIndexErrorrather thanUnexpectedDER.The fix adds the same length check the other helpers use. There are two new tests in
test_der.py, and both fail without the change.test_der.pyandtest_keys.pypass (274 tests).