diff options
author | Kjell Winblad <[email protected]> | 2019-03-28 15:46:04 +0100 |
---|---|---|
committer | Kjell Winblad <[email protected]> | 2019-03-29 15:54:36 +0100 |
commit | 3640c4ed502a93fc11480e48cc817e28dfe831e4 (patch) | |
tree | 432ce566020bea51893ef398c542ce3a7396b326 /erts/emulator/beam | |
parent | 060d9110ffb305d6ce5f974788948463e481203b (diff) | |
download | otp-3640c4ed502a93fc11480e48cc817e28dfe831e4.tar.gz otp-3640c4ed502a93fc11480e48cc817e28dfe831e4.tar.bz2 otp-3640c4ed502a93fc11480e48cc817e28dfe831e4.zip |
Fix out of memory bug in the implementation of maps
This commit fixes a bug that could cause a crash or memory usage to
grow until the machine ran out of memory when adding a key-value pair
to a map. This could happen when inserting a new key-value pair with a
key K1 containing a binary B1 into a map M having a key K2 with a
binary B2 if the following conditions were met:
* size(B1) >= 4294967296
* size(B2) >= 4294967296
* size(M) >= 32
* (size(B1) rem 4294967296) == (size(B2) rem 4294967296)
* the first (size(B1) rem 4294967296) bytes are the same both in B1
and B2
* substituting B1 in K1 with B2 would result in a term with the same
value as K2
The root cause of the bug is that the map implementation only hashed
the first (X modulo 4294967296) bytes of binaries so that different
binaries could get hashed to the same hash value independently of the
hash seed.
Diffstat (limited to 'erts/emulator/beam')
-rw-r--r-- | erts/emulator/beam/erl_utils.h | 1 | ||||
-rw-r--r-- | erts/emulator/beam/utils.c | 8 |
2 files changed, 4 insertions, 5 deletions
diff --git a/erts/emulator/beam/erl_utils.h b/erts/emulator/beam/erl_utils.h index 880febba8b..430ac305c5 100644 --- a/erts/emulator/beam/erl_utils.h +++ b/erts/emulator/beam/erl_utils.h @@ -69,7 +69,6 @@ int erts_fit_in_bits_int32(Sint32); int erts_fit_in_bits_uint(Uint); Sint erts_list_length(Eterm); int erts_is_builtin(Eterm, Eterm, int); -Uint32 block_hash(byte *, unsigned, Uint32); Uint32 make_hash2(Eterm); Uint32 make_hash(Eterm); Uint32 make_internal_hash(Eterm, Uint32 salt); diff --git a/erts/emulator/beam/utils.c b/erts/emulator/beam/utils.c index 36cfe0548e..0bbae65e28 100644 --- a/erts/emulator/beam/utils.c +++ b/erts/emulator/beam/utils.c @@ -1069,11 +1069,11 @@ do { \ #define HCONST 0x9e3779b9UL /* the golden ratio; an arbitrary value */ -Uint32 -block_hash(byte *k, unsigned length, Uint32 initval) +static Uint32 +block_hash(byte *k, Uint length, Uint32 initval) { Uint32 a,b,c; - unsigned len; + Uint len; /* Set up the internal state */ len = length; @@ -1749,7 +1749,7 @@ make_internal_hash(Eterm term, Uint32 salt) case SUB_BINARY_SUBTAG: { byte* bptr; - unsigned sz = binary_size(term); + Uint sz = binary_size(term); Uint32 con = HCONST_13 + hash; Uint bitoffs; Uint bitsize; |