From 89317508cd20a4db54fc1fd1ef328d34236bb634 Mon Sep 17 00:00:00 2001 From: Lei Zhiyuan Date: Thu, 19 Dec 2024 11:44:32 +0800 Subject: [PATCH] [ISSUE #9002] when bytebuffer is not enough, do not throw exception (#9003) * fix: when bytebuffer is not enough,we should wait for next instead of throw exception * fix: when bytebuffer is not enough,we should wait for next instead of throw exception --- .../src/main/java/org/apache/rocketmq/store/CommitLog.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/store/src/main/java/org/apache/rocketmq/store/CommitLog.java b/store/src/main/java/org/apache/rocketmq/store/CommitLog.java index d30691908b..ff96bf1066 100644 --- a/store/src/main/java/org/apache/rocketmq/store/CommitLog.java +++ b/store/src/main/java/org/apache/rocketmq/store/CommitLog.java @@ -432,8 +432,14 @@ public class CommitLog implements Swappable { public DispatchRequest checkMessageAndReturnSize(java.nio.ByteBuffer byteBuffer, final boolean checkCRC, final boolean checkDupInfo, final boolean readBody) { try { + if (byteBuffer.remaining() <= 4) { + return new DispatchRequest(-1, false /* fail */); + } // 1 TOTAL SIZE int totalSize = byteBuffer.getInt(); + if (byteBuffer.remaining() < totalSize - 4) { + return new DispatchRequest(-1, false /* fail */); + } // 2 MAGIC CODE int magicCode = byteBuffer.getInt(); @@ -628,6 +634,7 @@ public class CommitLog implements Swappable { return dispatchRequest; } catch (Exception e) { + log.error("checkMessageAndReturnSize failed, may can not dispatch", e); } return new DispatchRequest(-1, false /* success */);