Skip to content

Commit

Permalink
fix: when bytebuffer is not enough,we should wait for next instead of…
Browse files Browse the repository at this point in the history
… throw exception
  • Loading branch information
leizhiyuan committed Dec 2, 2024
1 parent adc1c74 commit 0e0abb7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions store/src/main/java/org/apache/rocketmq/store/CommitLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,14 @@ private void doNothingForDeadCode(final Object obj) {
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) {
return new DispatchRequest(-1, false /* fail */);
}

// 2 MAGIC CODE
int magicCode = byteBuffer.getInt();
Expand Down Expand Up @@ -624,6 +630,7 @@ public DispatchRequest checkMessageAndReturnSize(java.nio.ByteBuffer byteBuffer,

return dispatchRequest;
} catch (Exception e) {
log.error("checkMessageAndReturnSize failed, may can not dispatch", e);
}

return new DispatchRequest(-1, false /* success */);
Expand Down

0 comments on commit 0e0abb7

Please sign in to comment.