Skip to content

Commit d27e775

Browse files
author
Yuki Ito
committed
Validate uint size
1 parent 37599cc commit d27e775

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/msgpack_packer.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ pack_uint(N) when (N band 16#FFFF) =:= N ->
128128
pack_uint(N) when (N band 16#FFFFFFFF) =:= N->
129129
<< 16#CE:8, N:32/big-unsigned-integer-unit:1 >>;
130130
%% uint 64
131+
pack_uint(N) when (N band 16#FFFFFFFFFFFFFFFF) =:= N ->
132+
<< 16#CF:8, N:64/big-unsigned-integer-unit:1 >>;
133+
%% too big unit
131134
pack_uint(N) ->
132-
<< 16#CF:8, N:64/big-unsigned-integer-unit:1 >>.
135+
{error, {badarg, N}}.
133136

134137

135138
-spec pack_double(float()) -> binary().

test/msgpack_test.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ error_test_()->
253253
end},
254254
{"badarg too big int",
255255
?_assertEqual({error, {badarg, -16#8000000000000001}},
256-
pack(-16#8000000000000001))}
256+
pack(-16#8000000000000001))},
257+
{"badarg too big uint",
258+
?_assertEqual({error, {badarg, 16#10000000000000000}},
259+
pack(16#10000000000000000))}
257260
].
258261

259262
binary_test_() ->

0 commit comments

Comments
 (0)