fix(head): clearer NoSuchKey for prefix keys and validate part numbers (#1638)

This commit is contained in:
houseme
2026-01-29 15:40:51 +08:00
committed by GitHub
parent 7c497a30b2
commit e377c7e7f9
4 changed files with 115 additions and 21 deletions
+24
View File
@@ -1102,3 +1102,27 @@ pub(crate) async fn wrap_response_with_cors<T>(
response
}
/// Parse part number from Option<i32> to Option<usize> with validation
/// This function checks that the part number is greater than 0 and
/// converts it to usize, returning an error if invalid
///
/// # Arguments
/// * `part_number` - The optional part number as i32
/// * `op` - The operation name for logging purposes
///
/// # Returns
/// * `Ok(Some(usize))` if part number is valid
/// * `Ok(None)` if part number is None
/// * `Err(S3Error)` if part number is invalid (0 or overflow)
#[inline]
pub(crate) fn parse_part_number_i32_to_usize(part_number: Option<i32>, op: &'static str) -> S3Result<Option<usize>> {
match part_number {
None => Ok(None),
Some(n) if n <= 0 => Err(S3Error::with_message(
S3ErrorCode::InvalidArgument,
format!("{op}: invalid partNumber {n}, must be a positive integer"),
)),
Some(n) => Ok(Some(n as usize)),
}
}