Merge pull request 'api/s3: don't panic when a version has no blocks' (#1522) from rajsinghtech/garage:fix/multipart-empty-blocks into main-v2

Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/1522
This commit is contained in:
Alex
2026-09-06 07:49:47 +00:00
2 changed files with 13 additions and 2 deletions
+6 -1
View File
@@ -698,9 +698,14 @@ fn body_from_blocks_range(
// range, as well as their "true offset", which is their actual offset in the complete
// file (whereas block.offset designates the offset of the block WITHIN THE PART
// block.part_number, which is not the same in the case of a multipart upload)
// A version with no blocks yields no data, so the capacity hint must not index
// into an empty slice.
let capacity_block_size = all_blocks
.first()
.map_or(1024, |(_, b)| std::cmp::max(b.size, 1024));
let mut blocks: Vec<(VersionBlock, u64)> = Vec::with_capacity(std::cmp::min(
all_blocks.len(),
4 + ((end - begin) / std::cmp::max(all_blocks[0].1.size, 1024)) as usize,
4 + ((end - begin) / capacity_block_size) as usize,
));
let mut block_offset: u64 = 0;
for (_, b) in all_blocks.iter() {
+7 -1
View File
@@ -476,7 +476,13 @@ pub async fn handle_complete_multipart_upload(
size: total_size,
etag: etag.clone(),
},
final_version.blocks.items()[0].1.hash,
final_version
.blocks
.items()
.first()
.ok_or_internal_error("Multipart completion produced a final version with no blocks")?
.1
.hash,
));
let final_object = Object::new(*bucket_id, key.clone(), vec![object_version]);