diff options
Diffstat (limited to 'erts/emulator/test/binary_SUITE.erl')
-rw-r--r-- | erts/emulator/test/binary_SUITE.erl | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/erts/emulator/test/binary_SUITE.erl b/erts/emulator/test/binary_SUITE.erl index 0c4627d088..f143312f7c 100644 --- a/erts/emulator/test/binary_SUITE.erl +++ b/erts/emulator/test/binary_SUITE.erl @@ -62,6 +62,7 @@ t_hash/1, sub_bin_copy/1, bad_size/1, + unsorted_map_in_map/1, bad_term_to_binary/1, bad_binary_to_term_2/1,safe_binary_to_term2/1, bad_binary_to_term/1, bad_terms/1, more_bad_terms/1, @@ -97,6 +98,7 @@ all() -> big_binary_to_term, sub_bin_copy, bad_term_to_binary, t2b_system_limit, term_to_iovec, more_bad_terms, + unsorted_map_in_map, otp_5484, otp_5933, ordering, unaligned_order, gc_test, bit_sized_binary_sizes, otp_6817, otp_8117, deep, @@ -1104,6 +1106,36 @@ bad_bin_to_term(BadBin) -> bad_bin_to_term(BadBin,Opts) -> {'EXIT',{badarg,_}} = (catch binary_to_term_stress(BadBin,Opts)). +-define(MAP_EXT, 116). +-define(SMALL_INTEGER_EXT, 97). +-define(NIL, 106). +-define(MAP_SMALL_MAP_LIMIT, 32). + +%% OTP-18343: Decode unsorted flatmap as key in hashmap +unsorted_map_in_map(Config) when is_list(Config) -> + K1 = 1, + K2 = 2, + true = K1 < K2, + FMap = #{K1 => [], K2 => []}, + FMapBin = <<?MAP_EXT, 2:32, + %% unsorted list of key/value pairs + ?SMALL_INTEGER_EXT, K2, ?NIL, + ?SMALL_INTEGER_EXT, K1, ?NIL>>, + FMap = binary_to_term(<<131, FMapBin/binary>>), + + HKeys = lists:seq(1, ?MAP_SMALL_MAP_LIMIT+1), + HMap0 = maps:from_list([{K,[]} || K <- HKeys]), + HMap0Bin = term_to_binary(HMap0), + + %% Replace last key/value pair with FMap => [] + Prologue = binary:part(HMap0Bin, 0, byte_size(HMap0Bin)-3), + HMap1Bin = <<Prologue/binary, FMapBin/binary, ?NIL>>, + HMap1 = binary_to_term(HMap1Bin), + + %% Moment of truth, can we lookup key FMap + [] = maps:get(FMap, HMap1), + ok. + %% Test safety options for binary_to_term/2 safe_binary_to_term2(Config) when is_list(Config) -> bad_bin_to_term(<<131,100,0,14,"undefined_atom">>, [safe]), |