summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErlang/OTP <otp@erlang.org>2021-09-02 12:21:05 +0200
committerErlang/OTP <otp@erlang.org>2021-09-02 12:21:05 +0200
commit81dcba288bba0b09b6062e852223f3790db0d555 (patch)
treee86d9f44c64aa3b67d33dec6b1eaee70b2e57738
parent010d6b1d0aa6201fc12e28f8eae4ae704d690db8 (diff)
parent81805d631b6e196f2a71abc58b0c469186bec58e (diff)
downloaderlang-81dcba288bba0b09b6062e852223f3790db0d555.tar.gz
Merge branch 'bjorn/erts/fix-map-decoding/OTP-17594' into maint-24
* bjorn/erts/fix-map-decoding/OTP-17594: Make binary_to_term/1 more resilent against bad binaries
-rw-r--r--erts/emulator/beam/external.c5
-rw-r--r--erts/emulator/test/binary_SUITE.erl16
2 files changed, 20 insertions, 1 deletions
diff --git a/erts/emulator/beam/external.c b/erts/emulator/beam/external.c
index 6bfd9fa825..7935acf6ba 100644
--- a/erts/emulator/beam/external.c
+++ b/erts/emulator/beam/external.c
@@ -4894,7 +4894,6 @@ dec_term_atom_common:
(void) PSTACK_POP(hamt_array);
} while (!PSTACK_IS_EMPTY(hamt_array));
- PSTACK_DESTROY(hamt_array);
}
/* Iterate through all the (flat)maps and check for validity and sort keys
@@ -4906,6 +4905,9 @@ dec_term_atom_common:
if (!erts_validate_and_sort_flatmap((flatmap_t*)next))
goto error;
}
+
+ /* Now that no more errors can occur, the stacks can be destroyed safely. */
+ PSTACK_DESTROY(hamt_array);
WSTACK_DESTROY(flat_maps);
ASSERT((Eterm*)*dbg_resultp != NULL);
@@ -5619,6 +5621,7 @@ init_done:
if (n <= MAP_SMALL_MAP_LIMIT) {
heap_size += 3 + n + 1 + n;
} else {
+ CHKSIZE(2*n); /* Conservative size check */
heap_size += HASHMAP_ESTIMATED_HEAP_SIZE(n);
}
break;
diff --git a/erts/emulator/test/binary_SUITE.erl b/erts/emulator/test/binary_SUITE.erl
index 46434a8c1f..d8a4e6cddf 100644
--- a/erts/emulator/test/binary_SUITE.erl
+++ b/erts/emulator/test/binary_SUITE.erl
@@ -1442,6 +1442,22 @@ test_terms(Test_Func) ->
Test_Func(FF = fun binary_SUITE:all/0),
Test_Func(lists:duplicate(32, FF)),
+ %% Maps.
+ SmallMap = #{a => 1, b => 2, c => 3},
+ LargeMap1 = maps:from_list([{list_to_atom(integer_to_list(36#cafe+N*N*N, 36)),N} ||
+ N <- lists:seq(1, 33)]),
+ LargeMap2 = maps:from_list([{list_to_atom(integer_to_list(36#dead+N, 36)),N} ||
+ N <- lists:seq(1, 50)]),
+ MapWithMap = LargeMap1#{SmallMap => a, LargeMap1 => LargeMap2, LargeMap2 => LargeMap1,
+ [LargeMap1,LargeMap2] => LargeMap1,
+ <<"abc">> => SmallMap, <<"qrs">> => LargeMap1,
+ <<"xyz">> => LargeMap2 },
+ Test_Func(#{}),
+ Test_Func(SmallMap),
+ Test_Func(LargeMap1),
+ Test_Func(LargeMap2),
+ Test_Func(MapWithMap),
+
ok.
test_floats(Test_Func) ->