Skip to content

Commit 7233982

Browse files
authored
fix(ems): avoid abort in gc_migrate when heap metadata is corrupted (#4862)
Signed-off-by: zhenweijin <zhenwei.jin@intel.com>
1 parent fa7c2d3 commit 7233982

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

core/shared/mem-alloc/ems/ems_kfc.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,13 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size)
286286
while (cur < end) {
287287
size = hmu_get_size(cur);
288288

289-
#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
290289
if (size <= 0 || size > (uint32)((uint8 *)end - (uint8 *)cur)) {
291290
LOG_ERROR("[GC_ERROR]Heap is corrupted, heap migrate failed.\n");
291+
#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
292292
heap->is_heap_corrupted = true;
293+
#endif
293294
return GC_ERROR;
294295
}
295-
#endif
296296

297297
if (hmu_get_ut(cur) == HMU_FC && !HMU_IS_FC_NORMAL(size)) {
298298
tree_node = (hmu_tree_node_t *)cur;
@@ -315,15 +315,13 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size)
315315
cur = (hmu_t *)((char *)cur + size);
316316
}
317317

318-
#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
319318
if (cur != end) {
320319
LOG_ERROR("[GC_ERROR]Heap is corrupted, heap migrate failed.\n");
320+
#if BH_ENABLE_GC_CORRUPTION_CHECK != 0
321321
heap->is_heap_corrupted = true;
322+
#endif
322323
return GC_ERROR;
323324
}
324-
#else
325-
bh_assert(cur == end);
326-
#endif
327325

328326
return 0;
329327
}

0 commit comments

Comments
 (0)