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

mongorestore may terminate on invalid bson

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • 2.4.8
    • None
    • None
    • ALL

    Description

      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;
           }
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            james.wahlin@mongodb.com James Wahlin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: