Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1899

BsonBinary doesn't validate length

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • None
    • 3.0.3
    • BSON
    • None

    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)
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            ross@mongodb.com Ross Lawley
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: