Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public void doRead(ChannelHandlerContext ctx, ByteBuf buffer)
name.release();
buffer.skipBytes(1);
String[] parts = currentFileName.split(" ", 2);
if (parts.length < 2 || parts[1] == null || parts[1].isEmpty()) {
throw new IllegalArgumentException("Invalid file name format: " + currentFileName
Comment thread
rich7420 marked this conversation as resolved.
Outdated
+ ". Expected format: SIZE FILENAME");
Comment thread
rich7420 marked this conversation as resolved.
Outdated
}
Comment thread
rich7420 marked this conversation as resolved.
remaining = Long.parseLong(parts[0]);
Path destFilePath = destination.mapToDestination(parts[1]);
final Path destfileParent = destFilePath.getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.ozone.container.stream;

Comment thread
adoroszlai marked this conversation as resolved.
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;
Expand Down Expand Up @@ -113,6 +114,39 @@ public void splitContent() throws IOException {
assertEquals("yyy", getContent("bsd.txt"));
}

@Test
public void testInvalidFormatMissingSpace() {
final DirstreamClientHandler handler = new DirstreamClientHandler(
Comment thread
rich7420 marked this conversation as resolved.
Outdated
new DirectoryServerDestination(tmpDir));

IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
handler.doRead(null, wrap("123\n"));
});
Comment thread
rich7420 marked this conversation as resolved.
assertTrue(exception.getMessage().contains("Invalid file name format"));
}

@Test
public void testInvalidFormatEmptyFileName() {
final DirstreamClientHandler handler = new DirstreamClientHandler(
new DirectoryServerDestination(tmpDir));

IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
handler.doRead(null, wrap("123 \n"));
});
assertTrue(exception.getMessage().contains("Invalid file name format"));
}

@Test
public void testInvalidFormatOnlySize() {
final DirstreamClientHandler handler = new DirstreamClientHandler(
new DirectoryServerDestination(tmpDir));

IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
handler.doRead(null, wrap("12345\n"));
});
assertTrue(exception.getMessage().contains("Invalid file name format"));
}

@Nonnull
private String getContent(String name) throws IOException {
return new String(Files.readAllBytes(tmpDir.resolve(name)),
Expand Down