[SERVER-13802] Insert field validation stops at first Timestamp field Created: 30/Apr/14  Updated: 11/Jul/16  Resolved: 06/May/14

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.6.0
Fix Version/s: 2.6.2, 2.7.1

Type: Bug Priority: Major - P3
Reporter: Alexander Komyagin Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Operating System: ALL
Backport Completed:
Participants:

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



 Comments   
Comment by Githook User [ 15/May/14 ]

Author:

{u'username': u'erh', u'name': u'Eliot Horowitz', u'email': u'eliot@10gen.com'}

Message: SERVER-13802: fix insert validation with timestamps
(cherry picked from commit 3061ab54eb2cc642a279becfca0b93f5e17db117)
Branch: v2.6
https://github.com/mongodb/mongo/commit/4a92104637e03230e651f5c3e3997368f965e86c

Comment by Githook User [ 06/May/14 ]

Author:

{u'username': u'erh', u'name': u'Eliot Horowitz', u'email': u'eliot@10gen.com'}

Message: SERVER-13802: fix insert validation with timestamps
Branch: master
https://github.com/mongodb/mongo/commit/3061ab54eb2cc642a279becfca0b93f5e17db117

Generated at Thu Feb 08 03:32:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.