rich7420 commented on code in PR #11387:
URL: https://github.com/apache/ozone/pull/11387#discussion_r4704537813


##########
hadoop-ozone/s3gateway/pom.xml:
##########
@@ -167,6 +167,11 @@
       <groupId>org.apache.ratis</groupId>
       <artifactId>ratis-common</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.eclipse.angus</groupId>
+      <artifactId>jakarta.mail</artifactId>
+      <version>2.0.4</version>

Review Comment:
   Could the version move to the root `dependencyManagement`, and 
`angus-activation` be excluded? It needs `jakarta.activation` classes, but the 
pinned 1.2.2 API only has `javax.activation`.



##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/EndpointBase.java:
##########
@@ -470,7 +471,9 @@ protected Map<String, String> getCustomMetadataFromHeaders(
           throw ex;
         }
         List<String> values = requestHeaders.get(key);
-        String value = StringUtils.join(values, ",");
+        String value = values.stream()
+            .map(EndpointBase::decodeRfc2047MetadataValue)

Review Comment:
   Could one `TestEndpointBase` case check the 2 KB limit uses the decoded 
value? Measuring the raw header instead still passed all 2064 tests for me.



##########
hadoop-ozone/integration-test-s3/src/test/java/org/apache/hadoop/ozone/s3/awssdk/v2/AbstractS3SDKV2Tests.java:
##########
@@ -538,6 +538,22 @@ public void testPutObject() {
     assertEquals("\"37b51d194a7513e45b56f6524f2d51f2\"", 
getObjectResponse.eTag());
   }
 
+  @Test
+  public void testPutObjectWithRfc2047Metadata() {
+    final String bucketName = getBucketName();
+    final String keyName = getKeyName();
+    final String metadataValue = "café";

Review Comment:
   The SDK sends raw `café` (`é` as byte `e9`), so no encoded-word reaches S3G 
and decoding isn't exercised. Could this send `=?UTF-8?B?Y2Fmw6k=?=` instead?



##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectGet.java:
##########
@@ -282,6 +282,91 @@ public void getKeyWithCustomMetadata() throws IOException, 
OS3Exception {
         response.getHeaderString(CUSTOM_METADATA_HEADER_PREFIX + "meta1"));
   }
 
+  @Test
+  public void getKeyWithQEncodedRfc2047CustomMetadata()
+      throws IOException, OS3Exception {
+    final String keyName = "key-with-rfc2047-meta";
+    final String metaValue = "Hello Worldé";
+    final String encodedMetaValue = "=?UTF-8?Q?Hello_World=C3=A9?=";
+    MultivaluedMap<String, String> requestHeaders = new MultivaluedHashMap<>();
+    requestHeaders.putSingle(CUSTOM_METADATA_HEADER_PREFIX + "meta1",
+        encodedMetaValue);
+    when(headers.getRequestHeaders()).thenReturn(requestHeaders);
+
+    assertSucceeds(() -> put(rest, BUCKET_NAME, keyName, CONTENT));
+
+    assertEquals(metaValue, bucket.getKey(keyName).getMetadata().get("meta1"));
+    Response response = get(rest, BUCKET_NAME, keyName);
+    assertEquals(encodedMetaValue,
+        response.getHeaderString(CUSTOM_METADATA_HEADER_PREFIX + "meta1"));
+  }
+
+  @Test
+  public void getKeyWithBase64Rfc2047CustomMetadata()
+      throws IOException, OS3Exception {
+    final String keyName = "key-with-base64-rfc2047-meta";
+    final String metaValue = "café";
+    final String encodedMetaValue = "=?UTF-8?B?Y2Fmw6k=?=";
+    final String responseMetaValue = "=?UTF-8?Q?caf=C3=A9?=";
+    MultivaluedMap<String, String> requestHeaders = new MultivaluedHashMap<>();
+    requestHeaders.putSingle(CUSTOM_METADATA_HEADER_PREFIX + "meta1",
+        encodedMetaValue);
+    when(headers.getRequestHeaders()).thenReturn(requestHeaders);
+
+    assertSucceeds(() -> put(rest, BUCKET_NAME, keyName, CONTENT));
+
+    assertEquals(metaValue, bucket.getKey(keyName).getMetadata().get("meta1"));
+    Response response = get(rest, BUCKET_NAME, keyName);
+    assertEquals(responseMetaValue,
+        response.getHeaderString(CUSTOM_METADATA_HEADER_PREFIX + "meta1"));
+  }
+
+  @Test
+  public void getKeyDecodesMultipleRfc2047EncodedWords()
+      throws IOException, OS3Exception {
+    final String keyName = "key-with-multiple-rfc2047-words";
+    final String metaValue = "=?UTF-8?Q?a?= =?UTF-8?Q?b?=";
+    MultivaluedMap<String, String> requestHeaders = new MultivaluedHashMap<>();
+    requestHeaders.putSingle(CUSTOM_METADATA_HEADER_PREFIX + "meta1",
+        metaValue);
+    when(headers.getRequestHeaders()).thenReturn(requestHeaders);
+
+    assertSucceeds(() -> put(rest, BUCKET_NAME, keyName, CONTENT));
+
+    assertEquals("ab", bucket.getKey(keyName).getMetadata().get("meta1"));
+  }
+
+  @ParameterizedTest
+  @CsvSource({

Review Comment:
   Could `getKeyDecodesMultipleRfc2047EncodedWords` and 
`getKeyPreservesInvalidQEncodedMetadata` be rows here? An unknown-charset row 
would also cover the fallback: `return ""` there still passed all 2064 tests.



##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/EndpointBase.java:
##########
@@ -489,6 +492,29 @@ protected Map<String, String> getCustomMetadataFromHeaders(
     return customMetadata;
   }
 
+  private static String decodeRfc2047MetadataValue(String value) {
+    try {
+      return MimeUtility.decodeText(value);
+    } catch (UnsupportedEncodingException ex) {
+      return value;
+    }
+  }
+
+  private static String encodeRfc2047MetadataValue(String value) {
+    if (value.chars().allMatch(EndpointBase::isSafeAsciiMetadataCharacter)) {

Review Comment:
   This check rejects CR/LF, but `encodeText` leaves them unchanged, so 
`a\r\nb` (from `=?UTF-8?B?YQ0KYg==?=`) comes back with spaces instead. Could we 
force the encoding once this fails?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to