mongorestore may terminate on invalid bson

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.4.8
    • Component/s: None
    • None
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      When reading a document with invalid bson, mongorestore with object check enabled will:

      1. Call BSONObj.valid() to confirm whether valid
      2. If not it will iterate over the BSONElements
      3. For each iterated element it will:
        • Call BSONElement.validate() and print an error message if not valid.
        • Print to standard error the field name & bson type
        • Print to standard error the BSONElement

      The issue we run into is the printing of the BSONElement can itself trigger an assertion (due to the invalid bson) that will then throw an exception. The exception thrown is not caught and causes process termination. We should protect against this. If we do want to terminate on this error we should do so explicitly. The code in question is available here: https://github.com/mongodb/mongo/blob/r2.4.8/src/mongo/tools/tool.cpp#L511

      BSONObj o( buf );
      if ( _objcheck && ! o.valid() ) {
          cerr << "INVALID OBJECT - going try and pring out " << endl;
          cerr << "size: " << size << endl;
          BSONObjIterator i(o);
          while ( i.more() ) {
               BSONElement e = i.next();
               try {
                      e.validate();
               }
               catch ( ... ) {
                     cerr << "\t\t NEXT ONE IS INVALID" << endl;
               }
               cerr << "\t name : " << e.fieldName() << " " << e.type() << endl;
      
               // exception is thrown by this statement in the printing "e"
               cerr << "\t " << e << endl;
           }
      }
      

            Assignee:
            Unassigned
            Reporter:
            James Wahlin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: