Skip to content

GODRIVER-3303 Prevent out of bounds panic with length value #1735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions x/mongo/driver/wiremessage/wiremessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func ReadMsgSectionSingleDocument(src []byte) (doc bsoncore.Document, rem []byte
// data parsed into a slice of BSON documents.
func ReadMsgSectionDocumentSequence(src []byte) (identifier string, docs []bsoncore.Document, rem []byte, ok bool) {
length, rem, ok := readi32(src)
if !ok || int(length) > len(src) {
if !ok || int(length) > len(src) || length-4 < 0 {
return "", nil, rem, false
}

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

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

// ReadCompressedCompressedMessage reads the compressed wiremessage to dst.
func ReadCompressedCompressedMessage(src []byte, length int32) (msg []byte, rem []byte, ok bool) {
if len(src) < int(length) {
if len(src) < int(length) || length < 0 {
return nil, src, false
}
return src[:length], src[length:], true
Expand Down
Loading