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

Insert field validation stops at first Timestamp field

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.2, 2.7.1
    • Affects Version/s: 2.6.0
    • Component/s: Write Ops
    • Labels:
      None
    • ALL

      Issue Status as of May 14, 2014

      ISSUE SUMMARY
      When inserting documents, MongoDB validates the values for certain fields for correctness. For example, the _id field cannot be an array. A bug in the insertion code caused this validation to stop after the first encountered timestamp field and would therefore allow documents to be inserted that would normally not pass validation.

      USER IMPACT
      This can cause invalid documents to be stored in a collection. This in turn can cause problems when the invalid document is later read.

      WORKAROUNDS
      The issue only arises if users attempt to insert documents with invalid values. However, if users want to rely on this safety check, they can place any timestamp fields at the very end of the document to avoid this issue. Note that some drivers may not preserve the order of fields in a document.

      AFFECTED VERSIONS
      MongoDB 2.6.0 and 2.6.1 are affected by the issue.

      FIX VERSION
      The fix is included in the 2.6.2 production release.

      RESOLUTION DETAILS
      The problem was an erroneous break statement that would prematurely end validation. The break has been removed.

      Original description
      AD-MAC10G:~ alexander$ mongo
      MongoDB shell version: 2.6.0
      connecting to: test
      > db.test.insert({ts:Timestamp(0,0), _id : [1,2]})
      WriteResult({ "nInserted" : 1 })
      > db.test.find()
      { "_id" : [ 1, 2 ], "ts" : Timestamp(1398896760, 1) }
      > db.test.insert({_id : [1,2]})
      WriteResult({
      	"nInserted" : 0,
      	"writeError" : {
      		"code" : 2,
      		"errmsg" : "can't use an array for _id"
      	}
      })
      

      That's the problematic "break" :

      insert.cpp:58
                  BSONObjIterator i( doc );
                  while ( i.more() ) {
                      BSONElement e = i.next();
      
                      if ( e.type() == Timestamp && e.timestampValue() == 0 ) {
                          // we replace Timestamp(0,0) at the top level with a correct value
                          // in the fast pass, we just mark that we want to swap
                          hasTimestampToFix = true;
                          break;
                      }
      

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            alex.komyagin@mongodb.com Alexander Komyagin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: