You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by si...@apache.org on 2026/10/17 18:37:06 UTC
(ozone) 08/12: Improve continuation token decoding in S3 Gateway.
This is an automated email from the ASF dual-hosted git repository.
smengcl pushed a commit to branch ozone-2.1
in repository https://gitbox.apache.org/repos/asf/ozone.git
commit 9ea20908d296075fb5d8f48febff64f3809dda6f
Author: Siyao Meng <50...@users.noreply.github.com>
AuthorDate: Fri Oct 16 13:01:01 2026 -0700
Improve continuation token decoding in S3 Gateway.
(cherry picked from commit 30f21fb4f6e3b2f1bdb743e9a9fdaf0626c90b87)
---
.../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 571939d9ece..3db75347d48 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
@@ -94,7 +94,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: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org