Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-2250

Using bson that contains UTF-8 strings with null bytes fails

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.8.0
    • Affects Version/s: 1.6.3, 1.7.0
    • Component/s: libbson, libmongoc
    • None

      We ran into this when writing a Rust wrapper around libmongoc: https://github.com/thijsc/mongo-rust-driver

      We use the bson Rust library to prepare bson byte arrays that get converted to libmongoc bsons using bson_new_from_data. This happens here: https://github.com/thijsc/mongo-rust-driver/blob/master/src/bsonc.rs#L31

      Rust strings in the bson are converted to bson strings, these can contain null bytes as is allowed in the bson spec. When you try to insert these documents with either a normal insert or a bulk operation the insert fails with this error: "replacement document contains invalid keys)".

      After debugging this it looks like libmongoc sets the allow_null option to false when validating bson. I've found no way to override this. It seems like we should just be able to use this bson byte array, since it conforms to the spec. How could we call normal inserts and bulk operations in such a way they will allow this bson?

            Assignee:
            bjori Hannes Magnusson
            Reporter:
            thijs Thijs Cadier
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: