feat(memhub): 下溢写打印增强——块头/记录index/上下文/同ptr记录

SlotsBugTest 越过 can 问题后新信号:free 块前标记(block+8..9)被写零(前标记区是安全区,子块边界2^n>=32永不落此,free-list写只在block+0..7)→ 真实下溢/UAF写。

增强打印:hdr 块头值(判断 free-list 状态)、记录 index、±3 上下文记录、同 ptr 记录(F/A 标注),一次运行定位写入者。
This commit is contained in:
TermiNexus committed 2026-08-25 17:17:29 +08:00
1 parent 3ac48282a3
commit c9ccea4014
1 file changed
+25 -2
+25 -2
View File
@@ -894,8 +894,31 @@ class MemBuddy(MemManager):
m_fr: t.CUInt16T | t.CPtr = (t.CUInt16T | t.CPtr)(t.CVoid(p - 2, t.CPtr))
mfv_r: t.CUInt16T = m_fr[0]
if mfv_r != t.CUInt16T(MEMBUDDY_DET_MARKER):
stdio.printf("[DET] 下溢写: ptr=%llu size=%llu(free 后前标记被破坏,前标记=0x%04X)\n",
p, real_s, t.CUInt32T(mfv_r))
stdio.printf("[DET] 下溢写: ptr=%llu size=%llu(free 后前标记被破坏,前标记=0x%04X)hdr=0x%llX 记录[%zu]\n",
p, real_s, t.CUInt32T(mfv_r), hdr_v, i)
# 记录上下文 ±3(同越界写打印,定位 free 块分配/释放阶段)
stdio.printf("记录上下文: ")
ci_r: t.CInt = -3
while ci_r <= 3:
idx_r: t.CSizeT = t.CSizeT(t.CInt(i) + ci_r)
if idx_r < self._det_count:
cip_r: t.CUInt64T = self._det_records[idx_r * 2]
cis_r: t.CUInt64T = self._det_records[idx_r * 2 + 1]
stdio.printf("[%d]ptr=%llu sz=%llu ", ci_r, cip_r, cis_r & (free_flag - 1))
ci_r += 1
# 同 ptr 记录(free/active 复用链,判断块是否被二次分配/释放)
stdio.printf("\n同ptr记录: ")
ci3_r: t.CSizeT = 0
while ci3_r < self._det_count:
cp3_r: t.CUInt64T = self._det_records[ci3_r * 2]
cs3_r: t.CUInt64T = self._det_records[ci3_r * 2 + 1]
if cp3_r == p:
st_r: str = "A"
if (cs3_r & free_flag) != 0:
st_r = "F"
stdio.printf("[%zu]sz=%llu%s ", ci3_r, cs3_r & (free_flag - 1), st_r)
ci3_r += 1
stdio.printf("\n")
stdlib.exit(1)
i += 1
continue