File 4066-sys_core_fold-Stricten-tests-for-integers.patch of Package erlang

From 51ee678213119a7f3ea577fbfc57a9c133629ce7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Thu, 30 Jun 2022 05:17:07 +0200
Subject: [PATCH 6/6] sys_core_fold: Stricten tests for integers

---
 lib/compiler/src/beam_asm.erl      | 2 +-
 lib/compiler/src/sys_core_fold.erl | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/compiler/src/beam_asm.erl b/lib/compiler/src/beam_asm.erl
index 54616e6a51..bbbc844576 100644
--- a/lib/compiler/src/beam_asm.erl
+++ b/lib/compiler/src/beam_asm.erl
@@ -454,7 +454,7 @@ encode_arg({y, Y}, Dict) when is_integer(Y), Y >= 0 ->
 encode_arg({atom, Atom}, Dict0) when is_atom(Atom) ->
     {Index, Dict} = beam_dict:atom(Atom, Dict0),
     {encode(?tag_a, Index), Dict};
-encode_arg({integer, N}, Dict) when is_integer(N) ->
+encode_arg({integer, N}, Dict) ->
     %% Conservatively assume that all integers whose absolute
     %% value is greater than 1 bsl 128 will be bignums in
     %% the runtime system.
diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl
index d79753068f..9021d9eb5c 100644
--- a/lib/compiler/src/sys_core_fold.erl
+++ b/lib/compiler/src/sys_core_fold.erl
@@ -93,6 +93,9 @@
 -define(ASSERT(E), ignore).
 -endif.
 
+-define(MAX_FUNC_ARGS, 255).
+-define(IS_FUNC_ARITY(A), is_integer(A) andalso 0 =< A andalso A =< ?MAX_FUNC_ARGS).
+
 %% Variable value info.
 -record(sub, {v=[],                                 %Variable substitutions
               s=cerl_sets:new() :: cerl_sets:set(), %Variables in scope
@@ -1866,6 +1869,7 @@ case_data_pat_alias(P, BindTo0, TypeSig, Bs0) ->
 	    %% it to the variable.
 	    {Type,Arity} = TypeSig,
 	    Ann = [compiler_generated],
+            true = ?IS_FUNC_ARITY(Arity),
 	    Vars = make_vars(Ann, Arity),
 	    Data = cerl:ann_make_data(Ann, Type, Vars),
 	    Bs = [{BindTo0,P},{P,Data}|Bs0],
@@ -1923,7 +1927,7 @@ pat_to_expr(P) ->
 
 pat_to_expr_list(Ps) -> [pat_to_expr(P) || P <- Ps].
 
-make_vars(A, Max) ->
+make_vars(A, Max) when ?IS_FUNC_ARITY(Max) ->
     make_vars(A, 1, Max).
 
 make_vars(A, I, Max) when I =< Max ->
@@ -2443,6 +2447,7 @@ delay_build_1(Core0, TypeSig) ->
 	Core ->
 	    {Type,Arity} = TypeSig,
 	    Ann = [compiler_generated],
+            true = ?IS_FUNC_ARITY(Arity),
 	    Vars = make_vars(Ann, Arity),
 	    Data = cerl:ann_make_data(Ann, Type, Vars),
 	    {yes,Vars,Core,Data}
-- 
2.35.3

openSUSE Build Service is sponsored by