Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-36637

IDL objects should hold owned BSONObjs

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.1.4
    • Affects Version/s: None
    • Component/s: IDL
    • Labels:
      None
    • Fully Compatible
    • ALL
    • Platforms 2018-09-24
    • 0

      When parsing BSONType::Object elements, the automatically-generated parse method will store a view of BSON in the spec, rather than an owned copy. For example,

      document_source_out_gen.cpp
              else if (fieldName == kUniqueKeyFieldName) {
                  if (MONGO_unlikely(usedFields[kUniqueKeyBit])) {
                      ctxt.throwDuplicateField(element);
                  }
      
                  usedFields.set(kUniqueKeyBit);
      
                  if (MONGO_likely(ctxt.checkAndAssertType(element, Object))) {
                      _uniqueKey = element.Obj();
                  }
              }
      

      The spec then contains garbage if the original object used for parsing goes out-of-scope. Since the IDL already holds other owned types (e.g. std::string), we should strive to keep an owned copy of BSON.

      I don't think this affects existing users of the IDL, as in most usages the original command object is kept around for the lifetime of the command's execution. However, we'd like to serialize $out with the IDL in SERVER-36187, but our reparse-reserialization tests hit a segmentation violation.

            Assignee:
            mark.benvenuto@mongodb.com Mark Benvenuto
            Reporter:
            kyle.suarez@mongodb.com Kyle Suarez
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: