Skip to content

Commit e36833e

Browse files
committed
Added check that a decoded boolean value has either the value 0 or the value 1.
JAVA-1864
1 parent 5e50e18 commit e36833e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ protected byte doPeekBinarySubType() {
151151

152152
@Override
153153
protected boolean doReadBoolean() {
154-
return bsonInput.readByte() == 0x1;
154+
byte booleanByte = bsonInput.readByte();
155+
if (booleanByte != 0 && booleanByte != 1) {
156+
throw new BsonSerializationException(format("Expected a boolean value but found %d", booleanByte));
157+
}
158+
return booleanByte == 0x1;
155159
}
156160

157161
@Override

0 commit comments

Comments
 (0)