Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ public static Binary getBinaryFromMessageBody(ActiveMQObjectMessage message) thr
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,32 @@ public void testConvertObjectMessageToAmqpMessageWithAmqpValueBody() throws Exce
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();

Expand Down
Loading