From 98f35d3ff6e4b6b547618eae26936e69ebff45c0 Mon Sep 17 00:00:00 2001 From: Mathias Stearn Date: Tue, 5 Nov 2013 16:52:02 -0500 Subject: [PATCH] SERVER-11525 Better error message on oversized BSON in JS --- src/mongo/scripting/engine_v8.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mongo/scripting/engine_v8.cpp b/src/mongo/scripting/engine_v8.cpp index 605957ee08b..b51b28a38ff 100644 --- a/src/mongo/scripting/engine_v8.cpp +++ b/src/mongo/scripting/engine_v8.cpp @@ -1658,7 +1658,14 @@ namespace mongo { v8::Local value = o->Get(name); v8ToMongoElement(b, sname, value, depth + 1, &originalBSON); } - return b.obj(); + + const int sizeWithEOO = b.len() + 1/*EOO*/ - 4/*BSONObj::Holder ref count*/; + uassert(17260, str::stream() << "Converting from JavaScript to BSON failed: " + << "Object size " << sizeWithEOO << " exceeds limit of " + << BSONObjMaxUserSize << " bytes.", + sizeWithEOO <= BSONObjMaxUserSize); + + return b.obj(); // Would give an uglier error than above for oversized objects. } // --- random utils ----