[CXX-1116] result::insert_one/insert_many returns possibly-dangling references for inserted ids, no definition provided for result::insert_many::result() Created: 04/Nov/16  Updated: 15/Nov/16  Resolved: 15/Nov/16

Status: Closed
Project: C++ Driver
Component/s: Implementation
Affects Version/s: None
Fix Version/s: 3.0.3

Type: Bug Priority: Major - P3
Reporter: Igor Nikolaychuk Assignee: J Rassi
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

My code:

            std::vector<bsoncxx::document::value> documents;
            for(int i = 0; i < 100; i++) {
                documents.push_back(
                        bsoncxx::builder::stream::document{} << "i" << i << finalize);
            }
            auto result  = collection.insert_many(documents);
            if(result) {
                auto ids = result.value().inserted_ids();
                for (auto it = ids.begin(); it != ids.end(); ++it) {
                    //cout << it->second.get_oid().value.to_string() << endl;
                    auto second = it->second;
                    auto oId = second.get_oid();
                    auto idValue = oId.value;
                    string str = idValue.to_string();
                }
            }

I get the "src/bson/bson-iter.c:395 bson_iter_type(): precondition failed: iter->raw" exception on the "auto oId = second.get_oid();" line.



 Comments   
Comment by Githook User [ 15/Nov/16 ]

Author:

{u'username': u'jrassi', u'name': u'J. Rassi', u'email': u'rassi@10gen.com'}

Message: CXX-1116 result::insert_many needs to hold on to owned _id elements

Fixes a bug where the the return value of
result::insert_many::inserted_ids() could contain dangling references.
Branch: 3.1-dev
https://github.com/mongodb/mongo-cxx-driver/commit/885229ab019f47e2cd7abed5b058fd2758ad4fbe

Comment by Githook User [ 15/Nov/16 ]

Author:

{u'username': u'jrassi', u'name': u'J. Rassi', u'email': u'rassi@10gen.com'}

Message: CXX-1116 result::insert_one needs to hold on to owned copy of _id ele

Fixes a bug where the return value of
result::insert_one::inserted_id() could contain dangling references.
Branch: 3.1-dev
https://github.com/mongodb/mongo-cxx-driver/commit/189183165f6fcd7945e7e2cf09b3fb526ebd6e9d

Comment by Githook User [ 15/Nov/16 ]

Author:

{u'username': u'jrassi', u'name': u'J. Rassi', u'email': u'rassi@10gen.com'}

Message: CXX-1116 Provide definition of result::insert_many::result()

This method was declared as part of the API for this class, but no
definition was ever provided.
Branch: 3.1-dev
https://github.com/mongodb/mongo-cxx-driver/commit/ed86f1ec176c28a16e27d5bc09667d34db9c1fa3

Comment by J Rassi [ 15/Nov/16 ]

Resolving as fixed for 3.0.3. Thank you for reporting this issue, tvyxen!

Comment by Githook User [ 15/Nov/16 ]

Author:

{u'username': u'jrassi', u'name': u'J. Rassi', u'email': u'rassi@10gen.com'}

Message: CXX-1116 result::insert_many needs to hold on to owned _id elements

Fixes a bug where the the return value of
result::insert_many::inserted_ids() could contain dangling references.
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/885229ab019f47e2cd7abed5b058fd2758ad4fbe

Comment by Githook User [ 15/Nov/16 ]

Author:

{u'username': u'jrassi', u'name': u'J. Rassi', u'email': u'rassi@10gen.com'}

Message: CXX-1116 result::insert_one needs to hold on to owned copy of _id ele

Fixes a bug where the return value of
result::insert_one::inserted_id() could contain dangling references.
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/189183165f6fcd7945e7e2cf09b3fb526ebd6e9d

Comment by Githook User [ 15/Nov/16 ]

Author:

{u'username': u'jrassi', u'name': u'J. Rassi', u'email': u'rassi@10gen.com'}

Message: CXX-1116 Provide definition of result::insert_many::result()

This method was declared as part of the API for this class, but no
definition was ever provided.
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/ed86f1ec176c28a16e27d5bc09667d34db9c1fa3

Comment by David Golden [ 04/Nov/16 ]

We've confirmed this bug (and a similar one for insert_one). We'll be releasing a fix soon.

Comment by David Golden [ 04/Nov/16 ]

Thanks for the report. We'll try to replicate and let you know what we find.

Generated at Wed Feb 07 22:01:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.