Skip to content

Commit d309410

Browse files
chino540offkevinAlbs
authored andcommitted
CXX-2650 Fix limit value in open_download_stream (#927)
* [mongocxx/gridfs/bucket] Fix the cursor limit value in _open_download_stream * [mongocxx/gridfs/utest] Add a unit test to ensure limit value --------- Co-authored-by: Olivier Detour <[email protected]>
1 parent 2b21417 commit d309410

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/mongocxx/gridfs/bucket.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ downloader bucket::_open_download_stream(const client_session* session,
372372
"expected end to not be greater than the file length"};
373373
}
374374
if (file_len >= 0 && end_i64 < file_len) {
375-
const int64_t num_chunks =
376-
1 + ((end_i64 - start_i64) / static_cast<int64_t>(chunk_size));
375+
const int64_t num_chunks = (end_i64 / static_cast<int64_t>(chunk_size)) -
376+
(start_i64 / static_cast<int64_t>(chunk_size)) + 1;
377377
chunks_options.limit(num_chunks);
378378
}
379379
}

src/mongocxx/test/gridfs/bucket.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,12 @@ TEST_CASE("gridfs::bucket::download_to_stream works", "[gridfs::bucket]") {
938938
static_cast<std::size_t>(end));
939939
}
940940

941+
SECTION("across 2 chunks at the end") {
942+
const auto start = chunk_size - 1;
943+
const auto end = start + chunk_size - 1;
944+
check_downloaded_content(static_cast<std::size_t>(start),
945+
static_cast<std::size_t>(end));
946+
}
941947
SECTION("across 3 chunks") {
942948
const auto start = chunk_size / 2;
943949
const auto end = start + 2 * chunk_size;

0 commit comments

Comments
 (0)