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

Issues with empty binary value

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.12.0
    • Affects Version/s: 1.9.3
    • Component/s: None
    • Labels:
      None

      Trying to bson_append a binary value with NULL data asserts.

      bson_t ex = BSON_INITIALIZER;
      /* this asserts */
      bson_append_binary (&ex, "a", 1, BSON_SUBTYPE_BINARY, NULL /* data */, 0);
      

      The assertion occurs here.

      I think an empty binary value should be valid. From bsonspec.org:

      binary	::=	int32 subtype (byte*)
      

      Additionally, it seems we can decode JSON with an empty binary value:

      bson_t ex = BSON_INITIALIZER;
      #define JSON(s) #s
      char* json = JSON({"a": {"$binary": {"base64": "", "subType": "0"}}});
      bson_init_from_json (&ex, json, strlen(json), NULL);
      

      But we can get UBSAN errors when copying a bson_value_t of an empty binary value here:

      memcpy (dst->value.v_binary.data,
              src->value.v_binary.data,
              dst->value.v_binary.data_len);
      

            Assignee:
            kevin.albertson@mongodb.com Kevin Albertson
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: