[SERVER-26703] Inserting deeply-nested documents should fail with error Created: 19/Oct/16  Updated: 04/Apr/19  Resolved: 13/Mar/17

Status: Closed
Project: Core Server
Component/s: Security, Write Ops
Affects Version/s: None
Fix Version/s: 3.4.4, 3.5.5

Type: Improvement Priority: Major - P3
Reporter: J Rassi Assignee: Kyle Suarez
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Duplicate
is duplicated by SERVER-13878 Issue with aggregation pipeline Closed
is duplicated by SERVER-27978 Segfault updating deeply nested document Closed
Related
related to SERVER-29014 Consider prohibiting explaining an ex... Closed
Backwards Compatibility: Major Change
Backport Completed:
Backport Requested:
v3.4
Sprint: Query 2017-01-23, Query 2017-02-13, Query 2017-03-27
Participants:
Case:
Linked BF Score: 0

 Description   

From the MongoDB Limits and Thresholds docs page:

Nested Depth for BSON Documents

MongoDB supports no more than 100 levels of nesting for BSON documents.

The server should fail insertion of these documents with an error returned to the user. This would make the server's behavior consistent with the documentation.

Furthermore, if code in the server can assume that the nesting limit is fairly small, and the server can assert that the stack is of some known minimum size at time of process start, then recursive algorithms in the server can executed safely on these documents without concern of stack overflow.

To reproduce, run the following shell snippet.

function makeNestObj(depth){
    toret = {s : 1};
    for(i = 1; i < depth; i++){
        toret = {s : toret};
    }
    return toret;
}
db.foo.drop();
assert.writeError(db.foo.insert(makeNestObj(101)));  // Currently fails, should pass when this ticket is resolved.



 Comments   
Comment by Githook User [ 28/Mar/17 ]

Author:

{u'username': u'ksuarz', u'name': u'Kyle Suarez', u'email': u'kyle.suarez@mongodb.com'}

Message: SERVER-26703 reject commands exceeding the BSON depth limit

Any command sent to the server that exceeds the depth limit will fail. This also prevents users from
inserting documents that exceed the depth limit.

(cherry picked from commit d98143c5db73a8a9a49ef20e9e0f2732b4de5063)
Branch: v3.4
https://github.com/mongodb/mongo/commit/af8d7989c5593edd23d199be6f0bf8972aadba7a

Comment by Githook User [ 13/Mar/17 ]

Author:

{u'username': u'ksuarz', u'name': u'Kyle Suarez', u'email': u'kyle.suarez@mongodb.com'}

Message: SERVER-26703 reject commands exceeding the BSON depth limit

Any command sent to the server that exceeds the depth limit will fail. This also prevents users from
inserting documents that exceed the depth limit.
Branch: master
https://github.com/mongodb/mongo/commit/d98143c5db73a8a9a49ef20e9e0f2732b4de5063

Comment by Githook User [ 06/Mar/17 ]

Author:

{u'username': u'visemet', u'name': u'Max Hirschhorn', u'email': u'max.hirschhorn@mongodb.com'}

Message: Revert "SERVER-26703 reject commands exceeding the BSON depth limit"

This reverts commit c2b3178e0cae20a24bc9cc39a750bb864def17e3.
Branch: master
https://github.com/mongodb/mongo/commit/e2474a4d0d0fd1ba84d8edd201cf0c2334828c9e

Comment by Kyle Suarez [ 06/Mar/17 ]

I'm marking documentation changes as "Not Needed" because the BSON depth limit has always been around (see https://docs.mongodb.com/manual/reference/limits/#Nested-Depth-for-BSON-Documents). We may not have enforced it explicitly in the past, but I don't see a reason to change the docs unless someone disagrees.

Comment by Githook User [ 06/Mar/17 ]

Author:

{u'username': u'ksuarz', u'name': u'Kyle Suarez', u'email': u'kyle.suarez@mongodb.com'}

Message: SERVER-26703 reject commands exceeding the BSON depth limit

Any command sent to the server that exceeds the depth limit will fail. This also prevents users from
inserting documents that exceed the depth limit.
Branch: master
https://github.com/mongodb/mongo/commit/c2b3178e0cae20a24bc9cc39a750bb864def17e3

Generated at Thu Feb 08 04:12:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.