Skip to content

Commit e583aa6

Browse files
authored
GODRIVER-3303 Prevent out of bounds panic with length value (#1735)
1 parent 7f37ca1 commit e583aa6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

x/mongo/driver/wiremessage/wiremessage.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func ReadMsgSectionSingleDocument(src []byte) (doc bsoncore.Document, rem []byte
382382
// data parsed into a slice of BSON documents.
383383
func ReadMsgSectionDocumentSequence(src []byte) (identifier string, docs []bsoncore.Document, rem []byte, ok bool) {
384384
length, rem, ok := readi32(src)
385-
if !ok || int(length) > len(src) {
385+
if !ok || int(length) > len(src) || length-4 < 0 {
386386
return "", nil, rem, false
387387
}
388388

@@ -413,7 +413,7 @@ func ReadMsgSectionDocumentSequence(src []byte) (identifier string, docs []bsonc
413413
// sequence data.
414414
func ReadMsgSectionRawDocumentSequence(src []byte) (identifier string, data []byte, rem []byte, ok bool) {
415415
length, rem, ok := readi32(src)
416-
if !ok || int(length) > len(src) {
416+
if !ok || int(length) > len(src) || length-4 < 0 {
417417
return "", nil, rem, false
418418
}
419419

@@ -548,7 +548,7 @@ func ReadCompressedCompressorID(src []byte) (id CompressorID, rem []byte, ok boo
548548

549549
// ReadCompressedCompressedMessage reads the compressed wiremessage to dst.
550550
func ReadCompressedCompressedMessage(src []byte, length int32) (msg []byte, rem []byte, ok bool) {
551-
if len(src) < int(length) {
551+
if len(src) < int(length) || length < 0 {
552552
return nil, src, false
553553
}
554554
return src[:length], src[length:], true

0 commit comments

Comments
 (0)