Skip to content

Commit 3606a33

Browse files
committed
JAVA-2361: Check for inconsistent sizes when decoding the OldBinary subtype of Binary
1 parent 3146eab commit 3606a33

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

bson/src/main/org/bson/BsonBinaryReader.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ protected BsonBinary doReadBinaryData() {
136136
byte type = bsonInput.readByte();
137137

138138
if (type == BsonBinarySubType.OLD_BINARY.getValue()) {
139-
bsonInput.readInt32();
139+
int repeatedNumBytes = bsonInput.readInt32();
140+
if (repeatedNumBytes != numBytes - 4) {
141+
throw new BsonSerializationException("Binary sub type OldBinary has inconsistent sizes");
142+
}
140143
numBytes -= 4;
141144
}
142145
byte[] bytes = new byte[numBytes];

0 commit comments

Comments
 (0)