Skip to content

Commit 9318bc2

Browse files
committed
GODRIVER-2869 Test touchup (#1307)
1 parent 436a982 commit 9318bc2

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

x/bsonx/bsoncore/bsoncore_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -945,8 +945,12 @@ func TestNullBytes(t *testing.T) {
945945
}
946946

947947
func TestInvalidBytes(t *testing.T) {
948+
t.Parallel()
949+
948950
t.Run("read length less than 4 int bytes", func(t *testing.T) {
949-
_, src, ok := readLengthBytes([]byte{0x00, 0x00, 0x00, 0x01})
951+
t.Parallel()
952+
953+
_, src, ok := readLengthBytes([]byte{0x01, 0x00, 0x00, 0x00})
950954
assert.False(t, ok, "expected not ok response for invalid length read")
951955
assert.Equal(t, 4, len(src), "expected src to contain the size parameter still")
952956
})

x/mongo/driver/compression_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ func TestCompression(t *testing.T) {
4242
}
4343

4444
func TestDecompressFailures(t *testing.T) {
45+
t.Parallel()
46+
4547
t.Run("snappy decompress huge size", func(t *testing.T) {
48+
t.Parallel()
49+
4650
opts := CompressionOpts{
4751
Compressor: wiremessage.CompressorSnappy,
4852
UncompressedSize: 100, // reasonable size

x/mongo/driver/operation_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -892,3 +892,22 @@ func TestConvertI64PtrToI32Ptr(t *testing.T) {
892892
})
893893
}
894894
}
895+
896+
func TestDecodeOpReply(t *testing.T) {
897+
t.Parallel()
898+
899+
// GODRIVER-2869: Prevent infinite loop caused by malformatted wiremessage with length of 0.
900+
t.Run("malformatted wiremessage with length of 0", func(t *testing.T) {
901+
t.Parallel()
902+
903+
var wm []byte
904+
wm = wiremessage.AppendReplyFlags(wm, 0)
905+
wm = wiremessage.AppendReplyCursorID(wm, int64(0))
906+
wm = wiremessage.AppendReplyStartingFrom(wm, 0)
907+
wm = wiremessage.AppendReplyNumberReturned(wm, 0)
908+
idx, wm := bsoncore.ReserveLength(wm)
909+
wm = bsoncore.UpdateLength(wm, idx, 0)
910+
reply := Operation{}.decodeOpReply(wm)
911+
assert.Equal(t, []bsoncore.Document(nil), reply.documents)
912+
})
913+
}

0 commit comments

Comments
 (0)