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

smengcl 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 30f21fb4f6e Improve continuation token decoding in S3 Gateway.
30f21fb4f6e is described below

commit 30f21fb4f6e3b2f1bdb743e9a9fdaf0626c90b87
Author: Siyao Meng <[email protected]>
AuthorDate: Fri Oct 16 13:01:01 2026 -0700

    Improve continuation token decoding in S3 Gateway.
---
 .../org/apache/hadoop/ozone/s3/util/ContinueToken.java |  7 +++++++
 .../apache/hadoop/ozone/s3/util/TestContinueToken.java | 18 ++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/ContinueToken.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/ContinueToken.java
index 12c1d3ad826..81be5f0630d 100644
--- 
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/ContinueToken.java
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/ContinueToken.java
@@ -93,7 +93,14 @@ public static ContinueToken decodeFromString(String key) 
throws OS3Exception {
         checkHash(key, hex, digest);
 
         ByteBuffer buffer = ByteBuffer.wrap(Hex.decodeHex(hex));
+        if (buffer.remaining() < Integer.BYTES) {
+          throw new DecoderException("Continuation token is too short");
+        }
         int keySize = buffer.getInt();
+        // The token is client supplied, so never allocate more than it 
actually carries.
+        if (keySize < 0 || keySize > buffer.remaining()) {
+          throw new DecoderException("Invalid key size in continuation token: 
" + keySize);
+        }
 
         byte[] actualKeyBytes = new byte[keySize];
         buffer.get(actualKeyBytes);
diff --git 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestContinueToken.java
 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestContinueToken.java
index fc6c38980d2..b0fd1a20c52 100644
--- 
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestContinueToken.java
+++ 
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestContinueToken.java
@@ -18,9 +18,14 @@
 package org.apache.hadoop.ozone.s3.util;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
+import org.apache.commons.codec.digest.DigestUtils;
 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;
+import org.junit.jupiter.params.provider.ValueSource;
 
 /**
  * Test encode/decode of the continue token.
@@ -67,4 +72,17 @@ public void encodeDecodeNullDir() throws OS3Exception {
     assertEquals(ct, parsedToken);
   }
 
+  /**
+   * Tokens with a valid digest whose declared key size is larger than the 
token, negative, or missing.
+   */
+  @ParameterizedTest
+  @ValueSource(strings = {"7fffffff", "ffffffff", "00000005aa", "0000", ""})
+  public void decodeRejectsInvalidKeySize(String hex) {
+    String token = hex + "-" + DigestUtils.sha256Hex(hex);
+
+    OS3Exception ex = assertThrows(OS3Exception.class, () -> 
ContinueToken.decodeFromString(token));
+
+    assertEquals(S3ErrorTable.INVALID_ARGUMENT.getCode(), ex.getCode());
+  }
+
 }


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

Reply via email to