[JAVA-1899] BsonBinary doesn't validate length Created: 22/Jul/15  Updated: 19/Sep/16  Resolved: 19/Sep/16

Status: Closed
Project: Java Driver
Component/s: BSON
Affects Version/s: 3.0.3
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Ross Lawley Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Example:

        when:
        def json = '{ "_id" : { "$binary" : "QUJSV1RJRkdQRWVTRmY2OWZJU0FPQT09", "$type" : "3" } }'
        def bdoc = BsonDocument.parse(json)
 
        then:
        bdoc.toJson() == json
 
        then:
        def bin = bdoc.getBinary("_id")
        bin.data.size() == 16 // FAILS

Compared to Document:

Document.parse('{ "_id" : { "$binary" : "QUJSV1RJRkdQRWVTRmY2OWZJU0FPQT09", "$type" : "03" } }')
 
org.bson.BsonSerializationException: Expected length to be 16, not 24.
	at org.bson.codecs.UuidCodec.decode(UuidCodec.java:100)
	at org.bson.codecs.UuidCodec.decode(UuidCodec.java:36)
	at org.bson.codecs.DocumentCodec.readValue(DocumentCodec.java:212)
	at org.bson.codecs.DocumentCodec.decode(DocumentCodec.java:141)
	at org.bson.codecs.DocumentCodec.decode(DocumentCodec.java:45)
	at org.bson.Document.parse(Document.java:105)
	at org.bson.Document.parse(Document.java:90)
	at org.bson.BsonDocumentSpecification.test parse(BsonDocumentSpecification.groovy:287)



 Comments   
Comment by Jeffrey Yemin [ 19/Sep/16 ]

BsonValue subclasses such as BsonBinary should allow anything that the server does and not do any extra validation. Otherwise a user couldn't even fall back to BsonDocument to do a mongodump/restore of data that is corrupted in this way.

Generated at Thu Feb 08 08:55:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.