diff options
| author | Vincent de Phily <vincent.dephily@gmail.com> | 2010-07-09 13:29:47 +0200 |
|---|---|---|
| committer | Vincent de Phily <vincent.dephily@gmail.com> | 2010-07-09 13:29:47 +0200 |
| commit | 6abc120279ced47d899cd8596e4d48fc2171e2cf (patch) | |
| tree | 520610c041d9fc0c84c8d79c215d056505a568e8 | |
| parent | 64c36b7a8faac55d8dc80342f27929b5538c4307 (diff) | |
| download | msgpack-python-6abc120279ced47d899cd8596e4d48fc2171e2cf.tar.gz | |
erlang: Fix incomplete/invalid cases of unpack_/1
* fix list of invalid bytes was missing 3 possibilities (see type chart section of msgpack format spec)
* fix matching of invalid bytes to look at 1 byte instead of 2
* simplify 'incomplete' case : anything that's not complete or invalid is by definition incomplete
| -rw-r--r-- | erlang/msgpack.erl | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/erlang/msgpack.erl b/erlang/msgpack.erl index d1ba9cd..1c1eae9 100644 --- a/erlang/msgpack.erl +++ b/erlang/msgpack.erl @@ -236,24 +236,15 @@ unpack_(Bin) -> <<2#1001:4, L:4, Rest/binary>> -> unpack_array_(Rest, L, []); % array <<2#1000:4, L:4, Rest/binary>> -> unpack_map_(Rest, L, []); % map -% Incomplete / invalid data - <<F:16, _/binary>> when F==16#CA; F==16#CB; F==16#CC; - F==16#CD; F==16#CE; F==16#CF; - F==16#D0; F==16#D1; F==16#D2; - F==16#D3; F==16#DA; F==16#DB; - F==16#DC; F==16#DD; F==16#DE; - F==16#DF -> - throw(short); - <<F:16, _/binary>> when F==16#C1; - F==16#C7; F==16#C8; F==16#C9; - F==16#D5; F==16#D6; F==16#D7; - F==16#D8; F==16#D9 -> +% Invalid data + <<F, _/binary>> when F==16#C1; + F==16#C4; F==16#C5; F==16#C6; F==16#C7; F==16#C8; F==16#C9; + F==16#D4; F==16#D5; F==16#D6; F==16#D7; F==16#D8; F==16#D9 -> throw(badarg); +% Incomplete data (we've covered every complete/invalid case; anything left is incomplete) _ -> - throw(short) % or unknown/badarg? - end; -unpack_(<<>>)-> throw(short); -unpack_(<<2#101:3, _/binary>>) -> throw(short). + throw(short) + end. % ===== test codes ===== % -include_lib("eunit/include/eunit.hrl"). |
