Skip to content

Commit

Permalink
GODRIVER-2869 Test touchup (#1307)
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyang-hu committed Aug 1, 2023
1 parent 436a982 commit 9318bc2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion x/bsonx/bsoncore/bsoncore_test.go
Expand Up @@ -945,8 +945,12 @@ func TestNullBytes(t *testing.T) {
}

func TestInvalidBytes(t *testing.T) {
t.Parallel()

t.Run("read length less than 4 int bytes", func(t *testing.T) {
_, src, ok := readLengthBytes([]byte{0x00, 0x00, 0x00, 0x01})
t.Parallel()

_, src, ok := readLengthBytes([]byte{0x01, 0x00, 0x00, 0x00})
assert.False(t, ok, "expected not ok response for invalid length read")
assert.Equal(t, 4, len(src), "expected src to contain the size parameter still")
})
Expand Down
4 changes: 4 additions & 0 deletions x/mongo/driver/compression_test.go
Expand Up @@ -42,7 +42,11 @@ func TestCompression(t *testing.T) {
}

func TestDecompressFailures(t *testing.T) {
t.Parallel()

t.Run("snappy decompress huge size", func(t *testing.T) {
t.Parallel()

opts := CompressionOpts{
Compressor: wiremessage.CompressorSnappy,
UncompressedSize: 100, // reasonable size
Expand Down
19 changes: 19 additions & 0 deletions x/mongo/driver/operation_test.go
Expand Up @@ -892,3 +892,22 @@ func TestConvertI64PtrToI32Ptr(t *testing.T) {
})
}
}

func TestDecodeOpReply(t *testing.T) {
t.Parallel()

// GODRIVER-2869: Prevent infinite loop caused by malformatted wiremessage with length of 0.
t.Run("malformatted wiremessage with length of 0", func(t *testing.T) {
t.Parallel()

var wm []byte
wm = wiremessage.AppendReplyFlags(wm, 0)
wm = wiremessage.AppendReplyCursorID(wm, int64(0))
wm = wiremessage.AppendReplyStartingFrom(wm, 0)
wm = wiremessage.AppendReplyNumberReturned(wm, 0)
idx, wm := bsoncore.ReserveLength(wm)
wm = bsoncore.UpdateLength(wm, idx, 0)
reply := Operation{}.decodeOpReply(wm)
assert.Equal(t, []bsoncore.Document(nil), reply.documents)
})
}

0 comments on commit 9318bc2

Please sign in to comment.