You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by du...@apache.org on 2022/02/03 09:56:05 UTC
[rocketmq] branch develop updated: [ISSUE #3786] fix: The length of properties value should be checked before converting them to short. (#3788)
This is an automated email from the ASF dual-hosted git repository.
duhengforever pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new f219170 [ISSUE #3786] fix: The length of properties value should be checked before converting them to short. (#3788)
f219170 is described below
commit f21917085166237d5cf9331aad82c1a8c6f0f46c
Author: 彭小漪 <64...@qq.com>
AuthorDate: Thu Feb 3 17:54:46 2022 +0800
[ISSUE #3786] fix: The length of properties value should be checked before converting them to short. (#3788)
---
.../java/org/apache/rocketmq/common/message/MessageDecoder.java | 5 ++++-
store/src/main/java/org/apache/rocketmq/store/CommitLog.java | 7 ++++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java
index c94700e..9299127 100644
--- a/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java
+++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java
@@ -478,7 +478,10 @@ public class MessageDecoder {
String properties = messageProperties2String(message.getProperties());
byte[] propertiesBytes = properties.getBytes(CHARSET_UTF8);
//note properties length must not more than Short.MAX
- short propertiesLength = (short) propertiesBytes.length;
+ int propsLen = propertiesBytes.length;
+ if (propsLen > Short.MAX_VALUE)
+ throw new RuntimeException(String.format("Properties size of message exceeded, properties size: {}, maxSize: {}.", propsLen, Short.MAX_VALUE));
+ short propertiesLength = (short) propsLen;
int sysFlag = message.getFlag();
int storeSize = 4 // 1 TOTALSIZE
+ 4 // 2 MAGICCOD
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 73fd361..c10ffc3 100644
--- a/store/src/main/java/org/apache/rocketmq/store/CommitLog.java
+++ b/store/src/main/java/org/apache/rocketmq/store/CommitLog.java
@@ -1606,7 +1606,12 @@ public class CommitLog {
// properties from MessageExtBatch
String batchPropStr = MessageDecoder.messageProperties2String(messageExtBatch.getProperties());
final byte[] batchPropData = batchPropStr.getBytes(MessageDecoder.CHARSET_UTF8);
- final short batchPropLen = (short) batchPropData.length;
+ int batchPropDataLen = batchPropData.length;
+ if (batchPropDataLen > Short.MAX_VALUE) {
+ CommitLog.log.warn("Properties size of messageExtBatch exceeded, properties size: {}, maxSize: {}.", batchPropDataLen, Short.MAX_VALUE);
+ throw new RuntimeException("Properties size of messageExtBatch exceeded!");
+ }
+ final short batchPropLen = (short) batchPropDataLen;
int batchSize = 0;
while (messagesByteBuff.hasRemaining()) {