@@ -382,7 +382,7 @@ func ReadMsgSectionSingleDocument(src []byte) (doc bsoncore.Document, rem []byte
382
382
// data parsed into a slice of BSON documents.
383
383
func ReadMsgSectionDocumentSequence (src []byte ) (identifier string , docs []bsoncore.Document , rem []byte , ok bool ) {
384
384
length , rem , ok := readi32 (src )
385
- if ! ok || int (length ) > len (src ) {
385
+ if ! ok || int (length ) > len (src ) || length - 4 < 0 {
386
386
return "" , nil , rem , false
387
387
}
388
388
@@ -413,7 +413,7 @@ func ReadMsgSectionDocumentSequence(src []byte) (identifier string, docs []bsonc
413
413
// sequence data.
414
414
func ReadMsgSectionRawDocumentSequence (src []byte ) (identifier string , data []byte , rem []byte , ok bool ) {
415
415
length , rem , ok := readi32 (src )
416
- if ! ok || int (length ) > len (src ) {
416
+ if ! ok || int (length ) > len (src ) || length - 4 < 0 {
417
417
return "" , nil , rem , false
418
418
}
419
419
@@ -548,7 +548,7 @@ func ReadCompressedCompressorID(src []byte) (id CompressorID, rem []byte, ok boo
548
548
549
549
// ReadCompressedCompressedMessage reads the compressed wiremessage to dst.
550
550
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 {
552
552
return nil , src , false
553
553
}
554
554
return src [:length ], src [length :], true
0 commit comments