aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-03-19 14:40:32 +0100
committerBjörn Gustavsson <[email protected]>2018-03-19 14:47:48 +0100
commit4332bcdc9f6dd1b4c390a50df07b7e8ebf536f88 (patch)
treef982e652a9a60907529937ef66c26e6619853cfd
parent6751506b67e3ba6f4ce9eacd040ea269fca643fd (diff)
downloadotp-4332bcdc9f6dd1b4c390a50df07b7e8ebf536f88.tar.gz
otp-4332bcdc9f6dd1b4c390a50df07b7e8ebf536f88.tar.bz2
otp-4332bcdc9f6dd1b4c390a50df07b7e8ebf536f88.zip
core_parse: Fix handling of negative sizes in binaries
A literal negative size in binary construction would cause a crash.
-rw-r--r--lib/compiler/src/core_parse.yrl2
-rw-r--r--lib/compiler/test/bs_construct_SUITE.erl9
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/compiler/src/core_parse.yrl b/lib/compiler/src/core_parse.yrl
index 79a7cccd98..85444023c6 100644
--- a/lib/compiler/src/core_parse.yrl
+++ b/lib/compiler/src/core_parse.yrl
@@ -496,7 +496,7 @@ make_lit_bin(Acc, [#c_bitstr{val=I0,size=Sz0,unit=U0,type=Type0,flags=F0}|T]) ->
throw(impossible)
end,
if
- Sz =< 8, T =:= [] ->
+ 0 =< Sz, Sz =< 8, T =:= [] ->
<<Acc/binary,I:Sz>>;
Sz =:= 8 ->
make_lit_bin(<<Acc/binary,I:8>>, T);
diff --git a/lib/compiler/test/bs_construct_SUITE.erl b/lib/compiler/test/bs_construct_SUITE.erl
index da99aba346..7c5ad97f7e 100644
--- a/lib/compiler/test/bs_construct_SUITE.erl
+++ b/lib/compiler/test/bs_construct_SUITE.erl
@@ -303,7 +303,14 @@ fail(Config) when is_list(Config) ->
{'EXIT',{badarg,_}} = (catch <<42.0/integer>>),
{'EXIT',{badarg,_}} = (catch <<42/binary>>),
{'EXIT',{badarg,_}} = (catch <<an_atom/integer>>),
-
+
+ %% Bad literal sizes
+ Bin = i(<<>>),
+ {'EXIT',{badarg,_}} = (catch <<0:(-1)>>),
+ {'EXIT',{badarg,_}} = (catch <<Bin/binary,0:(-1)>>),
+ {'EXIT',{badarg,_}} = (catch <<0:(-(1 bsl 100))>>),
+ {'EXIT',{badarg,_}} = (catch <<Bin/binary,0:(-(1 bsl 100))>>),
+
ok.
float_bin(Config) when is_list(Config) ->