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 2e195ac0d84 HDDS-17658. S3 CreateMultipartUpload returns HTTP 500 if 
key matches existing dir in an FSO Bucket (#11922)
2e195ac0d84 is described below

commit 2e195ac0d844aa259c3cabad40f782321e83e89a
Author: Gargi Jaiswal <[email protected]>
AuthorDate: Wed Nov 4 16:25:18 2026 +0530

    HDDS-17658. S3 CreateMultipartUpload returns HTTP 500 if key matches 
existing dir in an FSO Bucket (#11922)
---
 .../hadoop/ozone/s3/endpoint/ObjectEndpoint.java   | 11 ++++++++
 .../s3/endpoint/TestInitiateMultipartUpload.java   | 31 ++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
index 2a426938edf..4de5b405fc8 100644
--- 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
@@ -836,6 +836,17 @@ public Response initializeMultipartUpload(
     } catch (OMException ex) {
       auditWriteFailure(context.getAction(), ex);
       getMetrics().updateInitMultipartUploadFailureStats(startNanos);
+      if (ex.getResult() == ResultCodes.NOT_A_FILE) {
+        // FSO rejects a multipart file whose key is an existing directory.
+        // Match PutObject: this is a client path error, not an internal 
failure.
+        OS3Exception os3Exception = newError(INVALID_REQUEST, key, ex);
+        os3Exception.setErrorMessage("An error occurred (InvalidRequest) " +
+            "when calling the PutObject/MPU PartUpload operation: " +
+            OmConfig.Keys.ENABLE_FILESYSTEM_PATHS + " is enabled Keys are" +
+            " considered as Unix Paths. Path has Violated FS Semantics " +
+            "which caused put operation to fail.");
+        throw os3Exception;
+      }
       throw newError(bucket, key, ex);
     } catch (Exception ex) {
       auditWriteFailure(context.getAction(), ex);
diff --git 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestInitiateMultipartUpload.java
 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestInitiateMultipartUpload.java
index 531601eb15f..1ed3c780fc1 100644
--- 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestInitiateMultipartUpload.java
+++ 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestInitiateMultipartUpload.java
@@ -22,6 +22,7 @@
 import static org.apache.hadoop.ozone.s3.util.S3Consts.STORAGE_CLASS_HEADER;
 import static org.apache.hadoop.ozone.s3.util.S3Consts.UNSIGNED_PAYLOAD;
 import static org.apache.hadoop.ozone.s3.util.S3Consts.X_AMZ_CONTENT_SHA256;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -39,13 +40,16 @@
 import java.io.IOException;
 import javax.ws.rs.core.HttpHeaders;
 import org.apache.hadoop.hdds.client.ECReplicationConfig;
+import org.apache.hadoop.hdds.client.ReplicationConfig;
 import org.apache.hadoop.ozone.OzoneConsts;
 import org.apache.hadoop.ozone.client.OzoneBucket;
 import org.apache.hadoop.ozone.client.OzoneClient;
 import org.apache.hadoop.ozone.client.OzoneClientStub;
 import org.apache.hadoop.ozone.client.OzoneVolume;
 import org.apache.hadoop.ozone.client.protocol.ClientProtocol;
+import org.apache.hadoop.ozone.om.OmConfig;
 import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.s3.exception.OS3Exception;
 import org.apache.hadoop.ozone.s3.exception.S3ErrorTable;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
@@ -129,6 +133,33 @@ public void testUploadPartRejectsFileAncestor(boolean 
wrapped) throws Exception
         () -> EndpointTestUtils.put(rest, bucket, key, 1, "upload-id", 
"content"));
   }
 
+  @ParameterizedTest
+  @ValueSource(strings = {"dir1", "dir1/"})
+  public void testInitiateMultipartUploadRejectsExistingDirectory(String key) 
throws Exception {
+    String bucket = OzoneConsts.S3_BUCKET;
+    OzoneClient client = new OzoneClientStub();
+    client.getObjectStore().createS3Bucket(bucket);
+    ObjectEndpoint rest = spy(getObjectEndpoint(client, 
mock(HttpHeaders.class)));
+    OzoneVolume volume = spy(rest.getVolume());
+    OzoneBucket ozoneBucket = spy(volume.getBucket(bucket));
+    doReturn(volume).when(rest).getVolume();
+    doReturn(ozoneBucket).when(volume).getBucket(bucket);
+    doThrow(new OMException("Can not write to directory: " + key, 
OMException.ResultCodes.NOT_A_FILE))
+        .when(ozoneBucket).initiateMultipartUpload(eq(key), 
any(ReplicationConfig.class), anyMap(), anyMap());
+
+    long failureBefore = rest.getMetrics().getInitMultiPartUploadFailure();
+    OS3Exception exception = assertErrorResponse(S3ErrorTable.INVALID_REQUEST,
+        () -> rest.initializeMultipartUpload(bucket, key));
+
+    assertEquals("An error occurred (InvalidRequest) " +
+        "when calling the PutObject/MPU PartUpload operation: " +
+        OmConfig.Keys.ENABLE_FILESYSTEM_PATHS + " is enabled Keys are" +
+        " considered as Unix Paths. Path has Violated FS Semantics " +
+        "which caused put operation to fail.", exception.getErrorMessage());
+    assertEquals(400, exception.getHttpCode());
+    assertEquals(1, rest.getMetrics().getInitMultiPartUploadFailure() - 
failureBefore);
+  }
+
   @Nonnull
   private ObjectEndpoint getObjectEndpoint(OzoneClient client,
       HttpHeaders headers) {


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

Reply via email to