You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2026/06/05 08:02:48 UTC

(opendal) branch main updated: fix(services): bound batch-delete result allocation against malformed server responses (#7683)

This is an automated email from the ASF dual-hosted git repository.

Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new ab8771d96 fix(services): bound batch-delete result allocation against malformed server responses (#7683)
ab8771d96 is described below

commit ab8771d968a3ac3938841e48c6c165a6504a0dfa
Author: tonghuaroot (童话) <to...@gmail.com>
AuthorDate: Fri Jun 5 16:02:42 2026 +0800

    fix(services): bound batch-delete result allocation against malformed server responses (#7683)
    
    Co-authored-by: tonghuaroot <23...@users.noreply.github.com>
---
 core/services/cloudflare-kv/src/deleter.rs | 6 +++++-
 core/services/oss/src/deleter.rs           | 5 ++++-
 core/services/s3/src/deleter.rs            | 5 ++++-
 core/services/swift/src/deleter.rs         | 5 ++++-
 4 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/core/services/cloudflare-kv/src/deleter.rs b/core/services/cloudflare-kv/src/deleter.rs
index c63ac54e6..c3b01027a 100644
--- a/core/services/cloudflare-kv/src/deleter.rs
+++ b/core/services/cloudflare-kv/src/deleter.rs
@@ -95,7 +95,11 @@ impl oio::BatchDelete for CloudflareKvDeleter {
         };
 
         let mut batched_result = BatchDeleteResult {
-            succeeded: Vec::with_capacity(result.successful_key_count),
+            // `successful_key_count` is taken verbatim from the server response; cap it to
+            // the number of keys we actually requested so a malicious/compromised endpoint
+            // cannot drive `Vec::with_capacity` to an abort/OOM. (`unsuccessful_keys` is an
+            // already-parsed Vec, so its length is inherently bounded.)
+            succeeded: Vec::with_capacity(result.successful_key_count.min(batch.len())),
             failed: Vec::with_capacity(result.unsuccessful_keys.len()),
         };
 
diff --git a/core/services/oss/src/deleter.rs b/core/services/oss/src/deleter.rs
index da900148d..8861b05e1 100644
--- a/core/services/oss/src/deleter.rs
+++ b/core/services/oss/src/deleter.rs
@@ -79,7 +79,10 @@ impl oio::BatchDelete for OssDeleter {
 
         let mut batched_result = BatchDeleteResult {
             succeeded: Vec::with_capacity(result.deleted.len()),
-            failed: Vec::with_capacity(keys.len() - result.deleted.len()),
+            // `result.deleted.len()` is server-controlled and may exceed `keys.len()`; use
+            // `saturating_sub` (mirroring services/tos) to avoid an unsigned underflow that
+            // wraps to a huge `with_capacity` (release: abort).
+            failed: Vec::with_capacity(keys.len().saturating_sub(result.deleted.len())),
         };
 
         for i in result.deleted {
diff --git a/core/services/s3/src/deleter.rs b/core/services/s3/src/deleter.rs
index 48831ffbb..d4dc62962 100644
--- a/core/services/s3/src/deleter.rs
+++ b/core/services/s3/src/deleter.rs
@@ -73,7 +73,10 @@ impl oio::BatchDelete for S3Deleter {
 
         let mut errors = result.error;
         let mut batched_result = BatchDeleteResult {
-            succeeded: Vec::with_capacity(batch.len() - errors.len()),
+            // `errors.len()` is server-controlled and may exceed `batch.len()`; use
+            // `saturating_sub` (mirroring services/tos) to avoid an unsigned underflow
+            // that wraps to a huge `with_capacity` (release: abort).
+            succeeded: Vec::with_capacity(batch.len().saturating_sub(errors.len())),
             failed: Vec::with_capacity(errors.len()),
         };
         for (path, op) in batch {
diff --git a/core/services/swift/src/deleter.rs b/core/services/swift/src/deleter.rs
index d429a0fa3..b3ec6f131 100644
--- a/core/services/swift/src/deleter.rs
+++ b/core/services/swift/src/deleter.rs
@@ -60,7 +60,10 @@ impl oio::BatchDelete for SwiftDeleter {
             serde_json::from_slice(&bs).map_err(new_json_deserialize_error)?;
 
         let mut batched_result = oio::BatchDeleteResult {
-            succeeded: Vec::with_capacity(batch.len() - result.errors.len()),
+            // `result.errors.len()` is server-controlled and may exceed `batch.len()`; use
+            // `saturating_sub` (mirroring services/tos) to avoid an unsigned underflow that
+            // wraps to a huge `with_capacity` (release: abort).
+            succeeded: Vec::with_capacity(batch.len().saturating_sub(result.errors.len())),
             failed: Vec::with_capacity(result.errors.len()),
         };