From 74ed6f2dbc484a59fc09a3bb27482759b3c5d990 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Tue, 25 Aug 2026 16:01:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(memhub):=20=E5=88=86=E9=85=8D=E9=87=8D?= =?UTF-8?q?=E5=8F=A0=E5=8D=B3=E6=97=B6=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SlotsBugTest 崩溃实锤:同一块被重复分配(记录表同 ptr 两条,[353]sz=7 与 [10298]sz=72)——7B 字符串缓冲与 72B Token 重叠,Token 初始化覆盖 buf 导致越界写,KwEntry cargs 只写 0/40 根因。 根因指向 MemBuddy free list 损坏(active 块混入 free list)。新增检测:每次 alloc 前将新块地址与 active 记录比对,命中即打印两个 size 并 exit(1),在第一次重叠处拦截,便于回溯具体分配调用。 --- includes/memhub.vp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/includes/memhub.vp b/includes/memhub.vp index c198ec5..1745e31 100644 --- a/includes/memhub.vp +++ b/includes/memhub.vp @@ -668,6 +668,20 @@ class MemBuddy(MemManager): m_t_d: t.CUInt16T | t.CPtr = (t.CUInt16T | t.CPtr)(t.CVoid(tail_d, t.CPtr)) m_t_d[0] = t.CUInt16T(MEMBUDDY_DET_MARKER) if self._det_records is not None: + # 分配重叠即时检测:新块地址是否已在 active 记录(同一块重复 + # 分配实锤——SlotsBugTest 7B buf 与 72B Token 同 ptr、cargs + # 只写 0/40 根因)。重叠 = MemBuddy free list 损坏(active 块 + # 混入 free list),在第一次重叠处拦截并打印两个 size。 + ff_d: t.CUInt64T = t.CUInt64T(1) << 63 + dup_i: t.CSizeT = 0 + while dup_i < self._det_count: + drp: t.CUInt64T = self._det_records[dup_i * 2] + drs: t.CUInt64T = self._det_records[dup_i * 2 + 1] + if drp == base_ret_d + 2 and (drs & ff_d) == 0: + stdio.printf("[DET] 分配重叠: 新alloc(size=%llu)与记录[%zu](sz=%llu)同地址 ptr=%llu(同一块重复分配,free list 损坏)\n", + t.CUInt64T(size), dup_i, drs & (ff_d - 1), base_ret_d + 2) + stdlib.exit(1) + dup_i += 1 if self._det_count >= self._det_cap: # 记录表满:stdlib.realloc 翻倍扩容(防 is_alive/_det_probe # 因容量耗尽漏检——SlotsBugTest 编译 includes 超 2M 次 alloc,