api/s3: don't panic when final multipart version has no blocks

CompleteMultipartUpload builds the final version and then reads
`final_version.blocks.items()[0]` unconditionally. When the assembled
version ends up with an empty block list the index panics and the
process dies before it can answer the request:

    panicked at src/api/s3/multipart.rs:479:3:
    index out of bounds: the len is 0 but the index is 0

Use `.first()` and return an internal error instead, matching how the
rest of this file handles missing data. The empty-block case is an
internal consistency condition rather than a malformed request, so it
maps to an internal error rather than a 4xx.

The same panic was reported earlier in #1403, at multipart.rs:483 on
v2.2.0. That report was closed without a fix after the reporter moved
off consistency_mode = "dangerous".

Closes #1521
This commit is contained in:
Raj Singh
2026-09-04 00:01:32 +00:00
parent c85597fd18
commit f38f001bad
+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]);