Skip to content

Fix integer overflow in GC threshold calculation #4546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions core/shared/mem-alloc/ems/ems_gc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,13 @@ typedef struct gc_heap_struct {
static inline void
gc_update_threshold(gc_heap_t *heap)
{
heap->gc_threshold =
heap->total_free_size * heap->gc_threshold_factor / 1000;
uint64_t result = (uint64_t)heap->total_free_size
* (uint64_t)heap->gc_threshold_factor / 1000;
/* heap->total_free_size * heap->gc_threshold_factor won't exceed
* 6^32(GC_HEAP_SIZE_MAX * GC_DEFAULT_THRESHOLD_FACTOR), so casting result
* to uint32_t is safe
*/
heap->gc_threshold = (uint32_t)result;
}

#define gct_vm_mutex_init os_mutex_init
Expand Down
Loading