[JAVA-1900] Can encode but not decode Binary UUID's with invalid lengths Created: 22/Jul/15  Updated: 19/Oct/16  Resolved: 29/Sep/16

Status: Closed
Project: Java Driver
Component/s: BSON
Affects Version/s: 3.0.0, 2.13.2
Fix Version/s: 3.4.0-rc1, 3.4.0

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

Issue Links:
Duplicate
Related

 Description   

Currently can't round trip

        byte[] data = [65, 66, 82, 87, 84, 73, 70, 71, 80, 69, 101, 83, 70, 102, 54, 57, 102, 73, 83, 65, 79, 65, 61, 61]
        byte type = 0x03
        def binary = new Binary(type, data)
 
        def document = new BasicDBObject("_id", binary)
 
        def encoder = new BasicBSONEncoder()
        def decoder = new BasicBSONDecoder()
        def callback = new BasicBSONCallback();
 
        then:
        def encoded = encoder.encode(document)
        decoder.decode(encoded, callback)  // FAILS



 Comments   
Comment by Githook User [ 29/Sep/16 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Fix decoding BSON binary UUID values in Iterables.

JAVA-1900
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/ec10aec00cd8fd5ffedac3647d72cead46a289f7

Comment by Ross Lawley [ 29/Sep/16 ]

PR: https://github.com/rozza/mongo-java-driver/pull/165

Comment by Githook User [ 22/Sep/16 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-1900: Ensure that BSON binary values of subtype 3 or 4 (UUID_LEGACY and UUID_STANDARD) can be decoded even if they have an unexpected size.

BSON binary representations of UUID should be 16 bytes, but the server doesn't enforce that constraint. Rather than throw an exception when decoding a
UUID value with length other than 16, the driver should instead decode it to an instance of org.bson.Binary rather than the expected java.util.UUID.

This way, clients expecting a UUID instance will still fail if casting to UUID, but at least they have the ability to control this behavior by doing type tests.
And clients that don't care one way or the other will continue to function in the face of bad data.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/8799770704adfcfea47ff6703db2ec6d9a42be9f

Comment by Jeffrey Yemin [ 20/Sep/16 ]

See also LazyBSONObject, which has a different code path to creating a UUID (and doesn't handle subtype 4)

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