[CXX-1322] gridfs::bucket::upload_from_stream and upload_from_stream_with_id infinitely loop on invalid ifstream without error bits set Created: 17/Apr/17  Updated: 25/Apr/17  Resolved: 25/Apr/17

Status: Closed
Project: C++ Driver
Component/s: Implementation
Affects Version/s: None
Fix Version/s: 3.2.0-rc0

Type: Bug Priority: Major - P3
Reporter: Samuel Rossi (Inactive) Assignee: Samuel Rossi (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CXX-1317 bucket::upload_from_stream() and buck... Closed

 Description   

If an invalid ifstream (e.g. one pointing to a non-existent file) without error bits set is passed to gridfs::bucket::upload_from_stream (or gridfs::bucket::upload_from_stream_with_id), the method will infinitely loop. This is because istream::read only throws an exception if `badbit` is set.

The most straightforward fix for this would be to set the error bits at the beginning of upload_from_stream_with_id so that errors will throw exceptions (and then document that this is the case):

source->exceptions(std::io::failbit | std::io::badbit);



 Comments   
Comment by Githook User [ 25/Apr/17 ]

Author:

{u'username': u'saghm', u'name': u'Saghm Rossi', u'email': u'saghmrossi@gmail.com'}

Message: CXX-1322 fix `bucket::upload_from_stream` throwing when EOF is read
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/3df45302c5a1603e8cece2cd2790a41eb7fb8706

Comment by Samuel Rossi (Inactive) [ 20/Apr/17 ]

Reopening due to bug discovered in the fix; as it is right now, `upload_from_stream` will throw due to hitting an EOF if the number of bytes the source stream yields isn't divisible by the chunk size.

Comment by Githook User [ 19/Apr/17 ]

Author:

{u'username': u'saghm', u'name': u'Saghm Rossi', u'email': u'saghmrossi@gmail.com'}

Message: CXX-1322 gridfs::bucket::upload_from_stream and upload_from_stream_with_id infinitely loop on invalid ifstream without error bits set
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/e96c30af7965d7128483e73954562b4648629b80

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