From 6e72dc30762f2b02ba74024c78911265bfdbf85d Mon Sep 17 00:00:00 2001 From: Zhengchao An Date: Sun, 28 Jun 2026 10:42:56 +0800 Subject: [PATCH] fix(ecstore): replace unsafe k.unwrap() in bucket_target_sys (#729) (#3982) fix(ecstore): replace k.unwrap() with safe pattern in bucket_target_sys Replace unsafe k.unwrap().as_str() with if let Some(key_str) pattern in 5 locations where HeaderMap iterator yields (Option, Value). This prevents potential panics if header names are invalid. Refs https://github.com/rustfs/backlog/issues/729 --- .../ecstore/src/bucket/bucket_target_sys.rs | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/crates/ecstore/src/bucket/bucket_target_sys.rs b/crates/ecstore/src/bucket/bucket_target_sys.rs index 239b7a2de..83c39b188 100644 --- a/crates/ecstore/src/bucket/bucket_target_sys.rs +++ b/crates/ecstore/src/bucket/bucket_target_sys.rs @@ -1525,9 +1525,10 @@ impl TargetClient { .customize() .map_request(move |mut req| { for (k, v) in headers.clone().into_iter() { - let key_str = k.unwrap().as_str().to_string(); - let value_str = v.to_str().unwrap_or("").to_string(); - req.headers_mut().insert(key_str, value_str); + if let Some(key_str) = k.map(|k| k.as_str().to_string()) { + let value_str = v.to_str().unwrap_or("").to_string(); + req.headers_mut().insert(key_str, value_str); + } } Result::<_, aws_smithy_types::error::operation::BuildError>::Ok(req) @@ -1586,9 +1587,10 @@ impl TargetClient { .customize() .map_request(move |mut req| { for (k, v) in headers.clone().into_iter() { - let key_str = k.unwrap().as_str().to_string(); - let value_str = v.to_str().unwrap_or("").to_string(); - req.headers_mut().insert(key_str, value_str); + if let Some(key_str) = k.map(|k| k.as_str().to_string()) { + let value_str = v.to_str().unwrap_or("").to_string(); + req.headers_mut().insert(key_str, value_str); + } } Result::<_, aws_smithy_types::error::operation::BuildError>::Ok(req) }) @@ -1625,9 +1627,10 @@ impl TargetClient { .customize() .map_request(move |mut req| { for (k, v) in headers.clone().into_iter() { - let key_str = k.unwrap().as_str().to_string(); - let value_str = v.to_str().unwrap_or("").to_string(); - req.headers_mut().insert(key_str, value_str); + if let Some(key_str) = k.map(|k| k.as_str().to_string()) { + let value_str = v.to_str().unwrap_or("").to_string(); + req.headers_mut().insert(key_str, value_str); + } } Result::<_, aws_smithy_types::error::operation::BuildError>::Ok(req) }) @@ -1661,9 +1664,10 @@ impl TargetClient { .customize() .map_request(move |mut req| { for (k, v) in headers.clone().into_iter() { - let key_str = k.unwrap().as_str().to_string(); - let value_str = v.to_str().unwrap_or("").to_string(); - req.headers_mut().insert(key_str, value_str); + if let Some(key_str) = k.map(|k| k.as_str().to_string()) { + let value_str = v.to_str().unwrap_or("").to_string(); + req.headers_mut().insert(key_str, value_str); + } } Result::<_, aws_smithy_types::error::operation::BuildError>::Ok(req) }) @@ -1694,9 +1698,10 @@ impl TargetClient { .customize() .map_request(move |mut req| { for (k, v) in headers.clone().into_iter() { - let key_str = k.unwrap().as_str().to_string(); - let value_str = v.to_str().unwrap_or("").to_string(); - req.headers_mut().insert(key_str, value_str); + if let Some(key_str) = k.map(|k| k.as_str().to_string()) { + let value_str = v.to_str().unwrap_or("").to_string(); + req.headers_mut().insert(key_str, value_str); + } } Result::<_, aws_smithy_types::error::operation::BuildError>::Ok(req) })