From 213d10838f0321d42a9f36f2b8a6873b8042c852 Mon Sep 17 00:00:00 2001 From: Konstantin Sharlaimov Date: Mon, 13 Jul 2026 21:14:19 +0200 Subject: [PATCH] fix(gc): correct leaking allocator bounds and overflow checks. Change heap-end comparison to > to prevent spurious OOM when heapptr exactly matches heapEnd. Add overflow check to prevent heap wrapping. --- src/runtime/gc_leaking.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/runtime/gc_leaking.go b/src/runtime/gc_leaking.go index 4ec9e6097..3f1595ff6 100644 --- a/src/runtime/gc_leaking.go +++ b/src/runtime/gc_leaking.go @@ -47,8 +47,14 @@ func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer { gcTotalAlloc += uint64(size) gcMallocs++ heapptr += size - for heapptr >= heapEnd { + if heapptr < addr { + // The allocation size overflowed the heap pointer. + runtimePanic("out of memory") + } + for heapptr > heapEnd { // Try to increase the heap and check again. + // Use > instead of >= because an allocation that exactly + // ends at heapEnd is still within heap boundaries. if growHeap() { continue }