Skip to content

Commit 8ee8ab3

Browse files
authored
Limit the minimal size of bh_hashmap (#2073)
Limit the minimal size of bh_hashmap to avoid creating hashmap with size 0, and `divide by zero` when calling bh_hash_map_find. Reported by #2008.
1 parent 0a7994a commit 8ee8ab3

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

core/shared/utils/bh_hashmap.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ bh_hash_map_create(uint32 size, bool use_lock, HashFunc hash_func,
3333
HashMap *map;
3434
uint64 total_size;
3535

36+
if (size < HASH_MAP_MIN_SIZE)
37+
size = HASH_MAP_MIN_SIZE;
38+
3639
if (size > HASH_MAP_MAX_SIZE) {
3740
LOG_ERROR("HashMap create failed: size is too large.\n");
3841
return NULL;

core/shared/utils/bh_hashmap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
extern "C" {
1313
#endif
1414

15+
/* Minimum initial size of hash map */
16+
#define HASH_MAP_MIN_SIZE 4
17+
1518
/* Maximum initial size of hash map */
1619
#define HASH_MAP_MAX_SIZE 65536
1720

0 commit comments

Comments
 (0)