Skip to content

Commit a22041f

Browse files
committed
fix bug: slice bounds out of range
1 parent 37c4db4 commit a22041f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

primitive_decoder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package y3
22

33
import (
44
"errors"
5+
"fmt"
56

67
"github.com/yomorun/y3-codec-golang/pkg/encoding"
78

@@ -53,6 +54,9 @@ func DecodePrimitivePacket(buf []byte) (packet *PrimitivePacket, endPos int, siz
5354

5455
logger.Debugf(">>> sizeL=%v, length=%v, pos=%v, endPos=%v", sizeL, p.length, pos, endPos)
5556

57+
if pos > endPos {
58+
return nil, 0, sizeL, fmt.Errorf("beyond the boundary, pos=%v, endPos=%v", pos, endPos)
59+
}
5660
p.valBuf = buf[pos:endPos]
5761
logger.Debugf("valBuf = %#X", p.valBuf)
5862

0 commit comments

Comments
 (0)