This is an automated email from the ASF dual-hosted git repository. adoroszlai pushed a commit to branch branch-2 in repository https://gitbox.apache.org/repos/asf/ratis.git
commit 05410aafe1b7f1c33b752a7674b623151834acdd Author: William Song <[email protected]> AuthorDate: Thu Apr 27 14:58:41 2023 +0800 RATIS-1837. Restrict reading maxChunkSize bytes each installSnapshot RPC (#877) (cherry picked from commit a29d3d825fe0630e45e427dbf9f15173a960d2b9) --- .../main/java/org/apache/ratis/server/storage/FileChunkReader.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ratis-server/src/main/java/org/apache/ratis/server/storage/FileChunkReader.java b/ratis-server/src/main/java/org/apache/ratis/server/storage/FileChunkReader.java index 47d70a771..dfed2790f 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/storage/FileChunkReader.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/storage/FileChunkReader.java @@ -20,6 +20,8 @@ package org.apache.ratis.server.storage; import org.apache.ratis.io.MD5Hash; import org.apache.ratis.proto.RaftProtos.FileChunkProto; import org.apache.ratis.thirdparty.com.google.protobuf.ByteString; +import org.apache.ratis.thirdparty.com.google.protobuf.UnsafeByteOperations; +import org.apache.ratis.util.IOUtils; import org.apache.ratis.util.JavaUtils; import java.io.Closeable; @@ -72,7 +74,9 @@ public class FileChunkReader implements Closeable { public FileChunkProto readFileChunk(int chunkMaxSize) throws IOException { final long remaining = info.getFileSize() - offset; final int chunkLength = remaining < chunkMaxSize ? (int) remaining : chunkMaxSize; - final ByteString data = ByteString.readFrom(in, chunkLength); + final byte[] chunkBuffer = new byte[chunkLength]; + IOUtils.readFully(in, chunkBuffer, 0, chunkBuffer.length); + final ByteString data = UnsafeByteOperations.unsafeWrap(chunkBuffer); // whether this chunk is the last chunk of current file final boolean isDone = offset + chunkLength == info.getFileSize(); final ByteString fileDigest;
