This commit is contained in:
@@ -159,6 +159,13 @@ func (f Fields) Unpack(r io.Reader, val reflect.Value, options *Options) error {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
size := length * field.Type.Resolve(options).Size()
|
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 {
|
if size < 8 {
|
||||||
buf = tmp[:size]
|
buf = tmp[:size]
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -36,6 +36,6 @@ type WalkInInfo struct {
|
|||||||
// Point: 直接给坐标x,y
|
// Point: 直接给坐标x,y
|
||||||
Point model.Pos `fieldDesc:"直接给坐标x,y"`
|
Point model.Pos `fieldDesc:"直接给坐标x,y"`
|
||||||
|
|
||||||
PathLen uint32 `struc:"sizeof=Path" `
|
PathLen uint32 `struc:"sizeof=Path"`
|
||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user