This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user