From 8988e84a0154676d78dba3882993e8a9c39903f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <12574910+72wo@users.noreply.github.com> Date: Sun, 8 Feb 2026 12:18:23 +0800 Subject: [PATCH] 1 --- common/utils/sturc/fields.go | 7 +++++++ logic/service/space/info.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/common/utils/sturc/fields.go b/common/utils/sturc/fields.go index 4aaca0ea8..02207b765 100644 --- a/common/utils/sturc/fields.go +++ b/common/utils/sturc/fields.go @@ -159,6 +159,13 @@ func (f Fields) Unpack(r io.Reader, val reflect.Value, options *Options) error { } } else { size := length * field.Type.Resolve(options).Size() + + // 添加大小限制,防止分配过大的内存 + const maxSize = 1024 * 1024 // 1MB 限制,可根据需求调整 + if size > maxSize { + return fmt.Errorf("buffer size too large: %d bytes, max allowed: %d", size, maxSize) + } + if size < 8 { buf = tmp[:size] } else { diff --git a/logic/service/space/info.go b/logic/service/space/info.go index 0fc2d1670..ff1d651a4 100644 --- a/logic/service/space/info.go +++ b/logic/service/space/info.go @@ -36,6 +36,6 @@ type WalkInInfo struct { // Point: 直接给坐标x,y Point model.Pos `fieldDesc:"直接给坐标x,y"` - PathLen uint32 `struc:"sizeof=Path" ` + PathLen uint32 `struc:"sizeof=Path"` Path string }