You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cs...@apache.org on 2026/07/29 00:30:24 UTC
(activemq) branch activemq-6.2.x updated: Fix AMQP Object message decompression (#2256) (#2263)
This is an automated email from the ASF dual-hosted git repository.
cshannon pushed a commit to branch activemq-6.2.x
in repository https://gitbox.apache.org/repos/asf/activemq.git
The following commit(s) were added to refs/heads/activemq-6.2.x by this push:
new e265abf38c Fix AMQP Object message decompression (#2256) (#2263)
e265abf38c is described below
commit e265abf38cdd3fbb702b4f07e6c57d92a4ea26f8
Author: Christopher L. Shannon <cs...@apache.org>
AuthorDate: Tue Jul 28 20:30:19 2026 -0400
Fix AMQP Object message decompression (#2256) (#2263)
This fixes the AmqpMessageSupport utility to correctly decompress the
body of Object Message's in all cases.
Previously the decompression could stop early and not decompress the entire stream of
data. This was due to the loop incorrectly casting the read int from the inflater
stream as a byte before comparing to -1 to look for end of stream.
This is incorrect because the read() method can return a value between -1 and 255.
Java uses Two's Complement to represent signed ints, so if the returned value int
is 255 and is cast to a byte it becomes -1. This meant that reading 255 would return -1
leading to the code to exit thinking end of stream has been reached.
(cherry picked from commit 2d60a8518d635205879fb8dc391bfb312755cb6a)
---
.../transport/amqp/message/AmqpMessageSupport.java | 4 ++--
.../message/JMSMappingOutboundTransformerTest.java | 25 +++++++++++++++++++++-
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/message/AmqpMessageSupport.java b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/message/AmqpMessageSupport.java
index 102a1701a5..6b6e034718 100644
--- a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/message/AmqpMessageSupport.java
+++ b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/message/AmqpMessageSupport.java
@@ -256,8 +256,8 @@ public final class AmqpMessageSupport {
InputStream iis = MarshallingSupport.createInflaterInputStream(
message.getMaxInflatedDataSize(), is)) {
- byte value;
- while ((value = (byte) iis.read()) != -1) {
+ int value;
+ while ((value = iis.read()) != -1) {
os.write(value);
}
diff --git a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/message/JMSMappingOutboundTransformerTest.java b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/message/JMSMappingOutboundTransformerTest.java
index c9da7149c9..2f0b03d1e3 100644
--- a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/message/JMSMappingOutboundTransformerTest.java
+++ b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/message/JMSMappingOutboundTransformerTest.java
@@ -580,9 +580,32 @@ public class JMSMappingOutboundTransformerTest {
assertTrue(value instanceof UUID);
}
+ @Test
+ public void testConvertCompressedObjectMessageToAmqpMessageByte255() throws Exception {
+ // This specific UUID tests a decompression edge case found for Objects messages and
+ // is used to verify AmqpMessageSupport.getBinaryFromMessageBody() is correct.
+ //
+ // Previously the decompression could stop early and not decompress the entire stream of
+ // data. This was due to the loop incorrectly casting the read int from the inflater
+ // stream as a byte before comparing to -1 to look for end of stream.
+ //
+ // This is incorrect because the read() method can return a value between -1 and 255.
+ // Java uses Two's Complement to represent signed ints, so if the returned value int
+ // is 255 and is cast to a byte it becomes -1. This meant that reading 255 would return -1
+ // leading to the code to exit thinking end of stream has been reached.
+ //
+ // This particular UUID includes a byte of 255 when decompressed to test this edge case.
+ testConvertCompressedObjectMessageToAmqpMessageWithDataBody(
+ UUID.fromString("14faffdc-387d-4e2e-8b44-748d47eaaf06"));
+ }
+
@Test
public void testConvertCompressedObjectMessageToAmqpMessageWithDataBody() throws Exception {
- ActiveMQObjectMessage outbound = createObjectMessage(TEST_OBJECT_VALUE, true);
+ testConvertCompressedObjectMessageToAmqpMessageWithDataBody(TEST_OBJECT_VALUE);
+ }
+
+ private void testConvertCompressedObjectMessageToAmqpMessageWithDataBody(UUID uuid) throws Exception {
+ ActiveMQObjectMessage outbound = createObjectMessage(uuid, true);
outbound.onSend();
outbound.storeContent();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@activemq.apache.org
For additional commands, e-mail: commits-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact