Only decode correctly encoded negative binaries

This commit is contained in:
Thomas Arts 2019-05-29 08:21:25 +02:00
parent ec0af8046a
commit f7a4c40c50

View File

@ -318,7 +318,12 @@ deserialize2(<<?POS_BIG_INT, Rest/binary>>) ->
Rest2}; Rest2};
deserialize2(<<?NEG_BITS, Rest/binary>>) -> deserialize2(<<?NEG_BITS, Rest/binary>>) ->
{Bint, Rest2} = aeser_rlp:decode_one(Rest), {Bint, Rest2} = aeser_rlp:decode_one(Rest),
{?FATE_BITS(-binary:decode_unsigned(Bint)), Rest2}; case binary:decode_unsigned(Bint) of
Pos when Pos > 0 ->
{?FATE_BITS(-Pos), Rest2};
N ->
error({illegal_parameter, neg_bits, N})
end;
deserialize2(<<?POS_BITS, Rest/binary>>) -> deserialize2(<<?POS_BITS, Rest/binary>>) ->
{Bint, Rest2} = aeser_rlp:decode_one(Rest), {Bint, Rest2} = aeser_rlp:decode_one(Rest),
{?FATE_BITS(binary:decode_unsigned(Bint)), Rest2}; {?FATE_BITS(binary:decode_unsigned(Bint)), Rest2};