diff options
author | Jason Rassi <rassi@10gen.com> | 2014-11-18 15:31:21 -0500 |
---|---|---|
committer | Jason Rassi <rassi@10gen.com> | 2014-11-18 15:32:08 -0500 |
commit | 20c218d3d3df17c820b9cd3e6399a2dec6755d94 (patch) | |
tree | 69a31e6a8a10563ef83ed406ff8cf09074da320f /src/mongo/db/matcher/path_test.cpp | |
parent | 813a2908ed3f35e1e395179983e0f09b0fee8fe5 (diff) | |
download | mongo-20c218d3d3df17c820b9cd3e6399a2dec6755d94.tar.gz |
SERVER-15899 BSONElementIterator::more() shouldn't overflow stack
BSONElementIterator::more() was using a stack frame per array
element traversed.
Diffstat (limited to 'src/mongo/db/matcher/path_test.cpp')
-rw-r--r-- | src/mongo/db/matcher/path_test.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/path_test.cpp b/src/mongo/db/matcher/path_test.cpp index eb58186e1e3..5602d4638c1 100644 --- a/src/mongo/db/matcher/path_test.cpp +++ b/src/mongo/db/matcher/path_test.cpp @@ -311,6 +311,26 @@ namespace mongo { ASSERT( !cursor.more() ); } + // SERVER-15899: test iteration using a path that generates no elements, but traverses a long + // array containing subdocuments with nested arrays. + TEST( Path, NonMatchingLongArrayOfSubdocumentsWithNestedArrays ) { + ElementPath p; + ASSERT( p.init( "a.b.x" ).isOK() ); + + // Build the document {a: [{b: []}, {b: []}, {b: []}, ...]}. + BSONObj subdoc = BSON( "b" << BSONArray() ); + BSONArrayBuilder builder; + for ( int i = 0; i < 100 * 1000; ++i ) { + builder.append( subdoc ); + } + BSONObj doc = BSON( "a" << builder.arr() ); + + BSONElementIterator cursor( &p, doc ); + + // The path "a.b.x" matches no elements. + ASSERT( !cursor.more() ); + } + TEST( SimpleArrayElementIterator, SimpleNoArrayLast1 ) { BSONObj obj = BSON( "a" << BSON_ARRAY( 5 << BSON( "x" << 6 ) << BSON_ARRAY( 7 << 9 ) << 11 ) ); SimpleArrayElementIterator i( obj["a"], false ); |