From b573ef3813baf14b9f4bec403b941b5f5d3e69e8 Mon Sep 17 00:00:00 2001 From: Konstantin Sharlaimov Date: Mon, 13 Jul 2026 20:57:04 +0200 Subject: [PATCH] fix(gc): correct old size calculation in block realloc. Using blocksPerStateByte instead of bytesPerBlock caused the old size to be underestimated for multi-block allocations, leading to data truncation on growing reallocations. --- src/runtime/gc_blocks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/gc_blocks.go b/src/runtime/gc_blocks.go index 2aadaeaf8..78387cb31 100644 --- a/src/runtime/gc_blocks.go +++ b/src/runtime/gc_blocks.go @@ -510,7 +510,7 @@ func realloc(ptr unsafe.Pointer, size uintptr) unsafe.Pointer { lastBlock := firstBlock.findHead() // Calculate the size of the original allocation body. - oldSize := uintptr(lastBlock-firstBlock)*blocksPerStateByte + (bytesPerBlock - unsafe.Sizeof(objHeader{})) + oldSize := uintptr(lastBlock-firstBlock)*bytesPerBlock + (bytesPerBlock - unsafe.Sizeof(objHeader{})) if size <= oldSize { // The requested size is less than the old size.