This is an automated email from the ASF dual-hosted git repository.
vrodionov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git
The following commit(s) were added to refs/heads/master by this push:
new d0648a5 RATIS-425: LogReader readBulk should validate number of
records
d0648a5 is described below
commit d0648a520a24ba2a9df6a6d7c3716cfdc3581b82
Author: Vlasimir Rodionov <[email protected]>
AuthorDate: Tue Jan 29 15:22:18 2019 -0800
RATIS-425: LogReader readBulk should validate number of records
---
.../org/apache/ratis/logservice/impl/LogReaderImpl.java | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/impl/LogReaderImpl.java
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/impl/LogReaderImpl.java
index 74aa7bf..0e4600a 100644
---
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/impl/LogReaderImpl.java
+++
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/impl/LogReaderImpl.java
@@ -30,6 +30,7 @@ import org.apache.ratis.logservice.proto.LogServiceProtos.*;
import org.apache.ratis.logservice.util.LogServiceProtoUtil;
import org.apache.ratis.protocol.Message;
import org.apache.ratis.protocol.RaftClientReply;
+import org.apache.ratis.thirdparty.com.google.common.base.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -67,6 +68,7 @@ public class LogReaderImpl implements LogReader {
@Override
public void seek(long recordId) throws IOException {
+ Preconditions.checkArgument(recordId >= 0, "recordId must be >= 0");
this.currentRecordId = recordId;
}
@@ -99,11 +101,11 @@ public class LogReaderImpl implements LogReader {
@Override
public void readNext(ByteBuffer buffer) throws IOException {
+
+ Preconditions.checkNotNull(buffer, "buffer is NULL" );
try {
- RaftClientReply reply =
- raftClient
- .sendReadOnly(Message.valueOf(LogServiceProtoUtil
- .toReadLogRequestProto(parent.getName(), currentRecordId,
1).toByteString()));
+ RaftClientReply reply =
raftClient.sendReadOnly(Message.valueOf(LogServiceProtoUtil
+ .toReadLogRequestProto(parent.getName(), currentRecordId,
1).toByteString()));
ReadLogReplyProto proto =
ReadLogReplyProto.parseFrom(reply.getMessage().getContent());
if (proto.hasException()) {
LogServiceException e = proto.getException();
@@ -121,6 +123,7 @@ public class LogReaderImpl implements LogReader {
@Override
public List<ByteBuffer> readBulk(int numRecords) throws IOException {
+ Preconditions.checkArgument(numRecords > 0, "number of records
must be greater than 0");
try {
RaftClientReply reply = raftClient
@@ -147,6 +150,9 @@ public class LogReaderImpl implements LogReader {
@Override
public int readBulk(List<ByteBuffer> buffers) throws IOException {
+ Preconditions.checkNotNull(buffers, "list of buffers is NULL" );
+ Preconditions.checkArgument(buffers.size() > 0, "list of buffers is
empty");
+
try {
RaftClientReply reply =
raftClient.sendReadOnly(Message.valueOf(LogServiceProtoUtil
.toReadLogRequestProto(parent.getName(), currentRecordId,
buffers.size()).toByteString()));