From 0352bb3a5b77458d1c816d314d891b96a4d4c58b Mon Sep 17 00:00:00 2001 From: Bala FA Date: Wed, 5 Jun 2024 14:27:19 +0530 Subject: [PATCH] fix range calculation in ComposeObject API (#140) Signed-off-by: Bala.FA --- src/client.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/client.cc b/src/client.cc index 5673315..94ffd56 100644 --- a/src/client.cc +++ b/src/client.cc @@ -326,14 +326,14 @@ ComposeObjectResponse Client::ComposeObject(ComposeObjectArgs args, while (size > 0) { part_number++; - size_t start_bytes = offset; - size_t end_bytes = start_bytes + utils::kMaxPartSize; - if (size < utils::kMaxPartSize) end_bytes = start_bytes + size; + size_t length = size; + if (length > utils::kMaxPartSize) length = utils::kMaxPartSize; + size_t end_bytes = offset + length - 1; utils::Multimap headerscopy; headerscopy.AddAll(headers); headerscopy.Add("x-amz-copy-source-range", - "bytes=" + std::to_string(start_bytes) + "-" + + "bytes=" + std::to_string(offset) + "-" + std::to_string(end_bytes)); UploadPartCopyArgs upc_args; @@ -350,8 +350,8 @@ ComposeObjectResponse Client::ComposeObject(ComposeObjectArgs args, } parts.push_back(Part(part_number, std::move(resp.etag))); } - offset = start_bytes; - size -= (end_bytes - start_bytes); + offset += length; + size -= length; } } }