Add input check to mp_unpack#601
Open
MagicalTux wants to merge 1 commit into
Open
Conversation
When nails >= size*8 the size - nail_bytes count underflowed, leading to an out-of-bounds read of the input buffer.
Member
|
Could you please add the reproducer(s) to CI? |
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.
mp_unpackdoes not validatesizeandnails. Whennails >= size*8(i.e.nail_bytes > size), the loop boundsize - nail_bytesunderflows to a value nearSIZE_MAX, so the inner loop runs essentially unbounded and reads progressively past theopbuffer — an out-of-bounds read.size == 0is an alternate trigger viasize - 1u.These parameters often come from an external serialization format, so an unchecked combination is reachable from untrusted input.
Fix: reject
size == 0andnails >= size*8withMP_VALbefore the loop.Confirmed with AddressSanitizer:
Reproducer:
mp_unpack(&r, 1, MP_MSB_FIRST, 2, MP_BIG_ENDIAN, 64, buf);