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 e51a88bfa76 HDDS-13943. Improve error message for malformed input in
DirstreamClientHandler (#9316)
e51a88bfa76 is described below
commit e51a88bfa769070c3b5c29a807b02cc69a41818c
Author: GUAN-HAO HUANG <[email protected]>
AuthorDate: Wed Nov 19 14:01:04 2025 +0800
HDDS-13943. Improve error message for malformed input in
DirstreamClientHandler (#9316)
---
.../container/stream/DirstreamClientHandler.java | 15 +++++++++-
.../stream/TestDirstreamClientHandler.java | 32 ++++++++++++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/stream/DirstreamClientHandler.java
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/stream/DirstreamClientHandler.java
index 05ed29cb2ed..3a5cd11ebf1 100644
---
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/stream/DirstreamClientHandler.java
+++
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/stream/DirstreamClientHandler.java
@@ -44,6 +44,10 @@
*/
public class DirstreamClientHandler extends ChannelInboundHandlerAdapter {
+ private static final String INVALID_FORMAT_MESSAGE =
+ "Expected format: <size> <filename> where <size> is a number and
<filename> "
+ + "is a string separated by a single space. Example: '1024
myfile.txt'";
+
private final StreamingDestination destination;
private boolean headerMode = true;
private String currentFileName = "";
@@ -80,7 +84,16 @@ public void doRead(ChannelHandlerContext ctx, ByteBuf buffer)
name.release();
buffer.skipBytes(1);
String[] parts = currentFileName.split(" ", 2);
- remaining = Long.parseLong(parts[0]);
+ if (parts.length < 2 || parts[1].isEmpty()) {
+ throw new IllegalArgumentException("Invalid file name format: " +
currentFileName + ". "
+ + INVALID_FORMAT_MESSAGE);
+ }
+ try {
+ remaining = Long.parseLong(parts[0]);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Invalid file name format: " +
currentFileName + ". "
+ + INVALID_FORMAT_MESSAGE, e);
+ }
Path destFilePath = destination.mapToDestination(parts[1]);
final Path destfileParent = destFilePath.getParent();
if (destfileParent == null) {
diff --git
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/stream/TestDirstreamClientHandler.java
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/stream/TestDirstreamClientHandler.java
index 7b996616fa5..946caf31f98 100644
---
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/stream/TestDirstreamClientHandler.java
+++
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/stream/TestDirstreamClientHandler.java
@@ -17,7 +17,9 @@
package org.apache.hadoop.ozone.container.stream;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import io.netty.buffer.ByteBuf;
@@ -27,8 +29,12 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
/**
* Test streaming client.
@@ -113,6 +119,32 @@ public void splitContent() throws IOException {
assertEquals("yyy", getContent("bsd.txt"));
}
+ @ParameterizedTest(name = "Invalid format: {0}")
+ @MethodSource("provideInvalidFormatTestCases")
+ public void testInvalidFormat(String testCaseName, String invalidInput) {
+ final DirstreamClientHandler handler = new DirstreamClientHandler(
+ new DirectoryServerDestination(tmpDir));
+
+ IllegalArgumentException exception =
assertThrows(IllegalArgumentException.class, () -> {
+ handler.doRead(null, wrap(invalidInput));
+ });
+ assertThat(exception)
+ .hasMessageContaining("Invalid file name format");
+ }
+
+ private static Stream<Arguments> provideInvalidFormatTestCases() {
+ return Stream.of(
+ // Test case: Missing space between size and filename
+ Arguments.of("Missing space", "123File.txt\n"),
+ // Test case: Empty filename after space
+ Arguments.of("Empty filename", "123 \n"),
+ // Test case: Only size number, no filename
+ Arguments.of("Only size", "12345\n"),
+ // Test case: Size is not a number
+ Arguments.of("Invalid size (non-numeric)", "oops filename.txt\n")
+ );
+ }
+
@Nonnull
private String getContent(String name) throws IOException {
return new String(Files.readAllBytes(tmpDir.resolve(name)),
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]