...
Original title: BSONElement.validate() success on invalid BSON There have been cases where BSONElement.validate() fails to recognize that an element is invalid. In the following code in tool.cpp we see the following: BSONObj o( buf ); >>> BSONObj.valid() returns false signifying a corrupt BSON object. 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() does not throw an exception and the "NEXT ONE" message is not printed. e.validate(); } catch ( ... ) { cerr << "\t\t NEXT ONE IS INVALID" << endl; } cerr << "\t name : " << e.fieldName() << " " << e.type() << endl; >>> An assertion is triggered on printing "e" (a BSONElement) to standard error. cerr << "\t " << e << endl; } } When we have a corrupt BSONElement, BSONElement.validate() should recognize and throw an exception.
xgen-internal-githook commented on Mon, 6 Jan 2014 21:00:43 +0000: Author: {u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'} Message: SERVER-11903 Fix bug in bson_validate_test support code Not using the passed-in fieldname invalidated the ErrorIsInId test case. Luckily it still passes with this fixed. Branch: master https://github.com/mongodb/mongo/commit/f2c66a95752628a1c51fd7b35148ff76e0718722 xgen-internal-githook commented on Mon, 6 Jan 2014 21:00:40 +0000: Author: {u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'} Message: SERVER-12260 Don't look for _id field name after EOO Fixes a bug in implementation of SERVER-11903 Branch: master https://github.com/mongodb/mongo/commit/8bfce9bcce36c2250f17fb51cadbdabb74754e10 redbeard0531 commented on Fri, 3 Jan 2014 17:56:07 +0000: Only backwards breaking for C++ driver users calling this function. xgen-internal-githook commented on Fri, 3 Jan 2014 17:52:06 +0000: Author: {u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'} Message: SERVER-11903 Remove BSONElement::validate() It was mostly used for improving the error messages about BSON that already failed validation, but it did not cover all validation cases. To replace this use case validateBSON was enhanced to include the _id of the invalid object in the error message. Branch: master https://github.com/mongodb/mongo/commit/ab48b396e5bc48cb27ce3bc2dbd28bf3b6a96851 redbeard0531 commented on Mon, 23 Dec 2013 21:31:35 +0000: Decision: kill BSONElement::validate() as described in my last comment. Will also look over validateBSON error messaging and make sure it provides enough information in the cases where we are using BSONElement::validate() today. redbeard0531 commented on Thu, 19 Dec 2013 21:16:38 +0000: There are a total of 5 places in the current codebase that call BSONElement::validate(). Other than in BSONObj::toString() they all follow the pattern of checking BSONObj::valid (which is just a wrapper around validateBSON) then on failure, checking BSONElement::validate() to provide more information in the error message. Those uses should be easy to change, assuming validateBSON can provide the needed information. I think the call in BSONObj::toString() should just be deleted since it doesn't seem necessary.
Click on a version to see all relevant bugs
MongoDB Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.