Permalink
Browse files

fix: huge value in object value makes decode failure (issue #1)

  • Loading branch information...
1 parent 12fc004 commit 190ebf0121ad09b7b180d579c73b31866e852e80 @hio committed Apr 5, 2012
Showing with 45 additions and 0 deletions.
  1. +6 −0 c_src/decode.c
  2. +39 −0 test/issue_001.erl
View
@@ -367,6 +367,12 @@ decode_bigval(Decoder* dec, const char* buf, long len)
dec->badvals[dec->badvals_len] = term;
++ dec->badvals_len;
}
+ /* drop object key */
+ if( dec->depth >= 0 )
+ {
+ assert(dec->stack[dec->depth] != NULL);
+ dec->stack[dec->depth]->key = THE_NON_VALUE;
+ }
return OK;
}
View
@@ -0,0 +1,39 @@
+-module(issue_001).
+-include_lib("eunit/include/eunit.hrl").
+
+issue_001_test_() ->
+ [
+ % reported cases.
+ % This calls returns a proper result:
+ ?_assertEqual(
+ {ok, {[ {<<"algorithm">>, <<"HMAC-SHA256">>}, {<<"credits">>, {[ {<<"buyer">>, 100000000000000} ]} } ]} },
+ json:decode(<<"{\"algorithm\":\"HMAC-SHA256\",\"credits\":{\"buyer\":100000000000000}}">>)
+ ),
+ ?_assertEqual(
+ {ok, {[ {<<"algorithm">>, <<"HMAC-SHA256">>}, {<<"credits">>, {[ {<<"buyer">>, 1000000000}, {<<"receiver">>, 100000000} ]} } ]} },
+ json:decode(<<"{\"algorithm\":\"HMAC-SHA256\",\"credits\":{\"buyer\":1000000000, \"receiver\":100000000}}">>)
+ ),
+ ?_assertEqual(
+ {ok, {[ {<<"algorithm">>, <<"HMAC-SHA256">>}, {<<"credits">>, {[ {<<"buyer">>, 1000000000}, {<<"receiver">>,10000000000000000000000} ]} } ]} },
+ json:decode(<<"{\"algorithm\":\"HMAC-SHA256\",\"credits\":{\"buyer\":1000000000, \"receiver\":10000000000000000000000}}">>)
+ ),
+
+ % But this one returns an {error,{69,invalid_internal_no_key_set}}:
+ ?_assertEqual(
+ {ok, {[ {<<"algorithm">>, <<"HMAC-SHA256">>}, {<<"credits">>, {[ {<<"buyer">>, 10000000000}, {<<"receiver">>, 100000000} ]} } ]} },
+ json:decode(<<"{\"algorithm\":\"HMAC-SHA256\",\"credits\":{\"buyer\":10000000000, \"receiver\":100000000}}">>)
+ ),
+
+ % simple case.
+ ?_assertEqual(
+ {ok, {[{<<"x">>, 123456789012345678901234567890}, {<<"y">>, 0}]}},
+ json:decode(<<"{\"x\":123456789012345678901234567890,\"y\":0}">>)
+ ),
+ ?_assertEqual(
+ {ok, {[{<<"a">>, 113456789012345678901234567890}, {<<"b">>,{[{<<"x">>, 123456789012345678901234567890}, {<<"y">>, 20}]}}, {<<"c">>, 30}]} },
+ json:decode(<<"{\"a\":113456789012345678901234567890,\"b\":{\"x\":123456789012345678901234567890,\"y\":20},\"c\":30}">>)
+ ),
+
+ ?_assert(true)
+ ].
+

0 comments on commit 190ebf0

Please sign in to comment.