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

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new eb767118f18 HDDS-17645. Reject non-positive max-parts in S3 ListParts 
(#11899)
eb767118f18 is described below

commit eb767118f18755e6a3425ef5ef6149d8ebeafc18
Author: Andy Huang <[email protected]>
AuthorDate: Mon Nov 2 21:22:31 2026 +0800

    HDDS-17645. Reject non-positive max-parts in S3 ListParts (#11899)
---
 .../ozone/s3/endpoint/MultipartKeyHandler.java     |  3 +++
 .../hadoop/ozone/s3/endpoint/TestListParts.java    | 30 ++++++++++++++++++----
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/MultipartKeyHandler.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/MultipartKeyHandler.java
index 70d17ed4b9e..ac371268d65 100644
--- 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/MultipartKeyHandler.java
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/MultipartKeyHandler.java
@@ -59,6 +59,9 @@ Response handleGetRequest(ObjectEndpoint.ObjectRequestContext 
context, String ke
     final AuditLogger.PerformanceStringBuilder perf = context.getPerf();
 
     try {
+      if (maxParts <= 0) {
+        throw newError(S3ErrorTable.INVALID_ARGUMENT, 
QueryParams.MAX_PARTS).withMessage("max-parts must be positive");
+      }
       ServerSideEncryption.rejectCustomerKey(getHeaders(), keyPath);
       int partMarker = parsePartNumberMarker(partNumberMarker);
       Response response = listParts(context.getVolume(), 
context.getBucketName(), keyPath, uploadId,
diff --git 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestListParts.java
 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestListParts.java
index 3bbe288f73e..1dfaaab04ba 100644
--- 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestListParts.java
+++ 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestListParts.java
@@ -56,6 +56,7 @@
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.CsvSource;
+import org.junit.jupiter.params.provider.ValueSource;
 
 /**
  * This class test list parts request.
@@ -89,12 +90,14 @@ public void setUp() throws Exception {
     }
   }
 
-  @Test
-  public void testListParts() throws Exception {
-    ListPartsResponse listPartsResponse = listParts(3, 0);
+  @ParameterizedTest
+  @ValueSource(ints = {1, 3, 1000})
+  public void testListParts(int maxParts) throws Exception {
+    ListPartsResponse listPartsResponse = listParts(maxParts, 0);
 
-    assertFalse(listPartsResponse.getTruncated());
-    assertEquals(3, listPartsResponse.getPartList().size());
+    assertEquals(maxParts < 3, listPartsResponse.getTruncated());
+    assertEquals(Math.min(maxParts, 3), 
listPartsResponse.getPartList().size());
+    assertEquals(maxParts, listPartsResponse.getMaxParts());
   }
 
   @Test
@@ -117,6 +120,23 @@ public void testListPartsWithUnknownUploadID() {
         () -> EndpointTestUtils.listParts(rest, OzoneConsts.S3_BUCKET, 
"no-such-key", "no-such-upload", 2, 0));
   }
 
+  @ParameterizedTest
+  @ValueSource(ints = {0, -1, Integer.MIN_VALUE})
+  public void testListPartsRejectsNonPositiveMaxParts(int maxParts) throws 
Exception {
+    ClientProtocol proxy = mock(ClientProtocol.class);
+    ObjectEndpoint endpoint = newEndpoint(proxy, mock(HttpHeaders.class));
+    when(proxy.listParts("volume1", "bucket1", "key1", "upload1", 0, maxParts))
+        .thenThrow(new IllegalArgumentException("Max Parts Should be greater 
than zero"));
+    long failures = endpoint.getMetrics().getListPartsFailure();
+
+    OS3Exception error = assertErrorResponse(S3ErrorTable.INVALID_ARGUMENT,
+        () -> EndpointTestUtils.listParts(endpoint, "bucket1", "key1", 
"upload1", maxParts, 0));
+
+    assertThat(error.getResource()).isEqualTo("max-parts");
+    assertThat(endpoint.getMetrics().getListPartsFailure()).isEqualTo(failures 
+ 1);
+    verify(proxy, never()).listParts("volume1", "bucket1", "key1", "upload1", 
0, maxParts);
+  }
+
   @ParameterizedTest
   @CsvSource({", 0", "'', 0", "owner, 1"})
   public void testListPartsOnlyLooksUpBucketForOwner(String expectedOwner, int 
bucketLookups) throws Exception {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to