ystero-dev / hampi

Rust ASN.1 Toolkit
Other
43 stars 18 forks source link

Fix panic when too many bits in bitvec for integer #92

Closed nathaniel-bennett closed 1 year ago

nathaniel-bennett commented 1 year ago

When a region greater than 128 bits is loaded into a u128 via the load_be bitvec method, a panic will occur due to a check in the bitvec library. This can occur in the decode_bits_as_integer hampi method when a bit length greater than 128 is passed into it, which in turn happens in the decode_unconstrained_whole_number_common method. To ensure this crash cannot happen due to parsing unconstrained ASN.1 input, I've made a change that returns an error instead of crashing.

Additionally, this pull request fixes an implicit u128 to i128 conversion error when values are greater than i128::MAX; I've also changed this so that the value returns an error instead of crashing.