File 0788-Fix-error-report-for-large-integers-in-unicode-chara.patch of Package erlang
From d2560b13eb43d689addfcd9a7b422c20f97d958c Mon Sep 17 00:00:00 2001
From: Rickard Green <rickard@erlang.org>
Date: Tue, 1 Oct 2019 15:37:45 +0200
Subject: [PATCH] Fix error report for large integers in
unicode:characters_to_*()
---
erts/emulator/beam/erl_unicode.c | 11 +++++++++++
lib/stdlib/src/stdlib.app.src | 2 +-
lib/stdlib/test/unicode_SUITE.erl | 26 ++++++++++++++++++++++++--
3 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/erts/emulator/beam/erl_unicode.c b/erts/emulator/beam/erl_unicode.c
index 9fd3012888..86027a8b90 100644
--- a/erts/emulator/beam/erl_unicode.c
+++ b/erts/emulator/beam/erl_unicode.c
@@ -455,6 +455,17 @@ L_Again: /* Restart with sublist, old listend was pushed on stack */
objp = list_val(ioterm);
obj = CAR(objp);
}
+ } else if (is_big(obj)) {
+ /*
+ * This is obviously an error, but we
+ * need do_build_utf8() to produce the
+ * error; otherwise, we will generate
+ * a badarg instead of the informative
+ * error tuple.
+ */
+ DESTROY_ESTACK(stack);
+ *costp = cost;
+ return need;
} else {
DESTROY_ESTACK(stack);
*costp = cost;
diff --git a/lib/stdlib/test/unicode_SUITE.erl b/lib/stdlib/test/unicode_SUITE.erl
index e01ba3fbb0..ada79dbe65 100644
--- a/lib/stdlib/test/unicode_SUITE.erl
+++ b/lib/stdlib/test/unicode_SUITE.erl
@@ -33,7 +33,8 @@
ex_binaries_errors_utf16_little/1,
ex_binaries_errors_utf16_big/1,
ex_binaries_errors_utf32_little/1,
- ex_binaries_errors_utf32_big/1]).
+ ex_binaries_errors_utf32_big/1,
+ huge_illegal_code_points/1]).
suite() ->
[{ct_hooks,[ts_install_cth]},
@@ -44,7 +45,8 @@ all() ->
utf16_illegal_sequences_bif, random_lists, roundtrips,
latin1, exceptions,
binaries_errors_limit,
- {group,binaries_errors}].
+ {group,binaries_errors},
+ huge_illegal_code_points].
groups() ->
[{binaries_errors,[parallel],
@@ -919,6 +921,26 @@ normalize(_) ->
_ ->
ok
end.
+huge_illegal_code_points(Config) when is_list(Config) ->
+ LargeList = lists:duplicate(1024, $x),
+ Pre = ["ok part", [[LargeList]]],
+ Post = ["error tail", [[LargeList]]],
+ huge_illegal_code_points_aux(Pre, 1 bsl 27, Post),
+ huge_illegal_code_points_aux(Pre, 1 bsl 28, Post),
+ huge_illegal_code_points_aux(Pre, 1 bsl 32, Post),
+ huge_illegal_code_points_aux(Pre, 1 bsl 59, Post),
+ huge_illegal_code_points_aux(Pre, 1 bsl 60, Post),
+ huge_illegal_code_points_aux(Pre, 1 bsl 64, Post),
+ ok.
+
+huge_illegal_code_points_aux(Pre, Error, Post) ->
+ ErrorList = [Error|Post],
+ In = [Pre | ErrorList],
+ FlatPre = lists:flatten(Pre),
+ {error, FlatPre, ErrorList} = unicode:characters_to_list(In),
+ BinPre = list_to_binary(FlatPre),
+ {error, BinPre, ErrorList} = unicode:characters_to_binary(In),
+ ok.
%%
%% Diverse utilities
--
2.16.4