diff --git a/activemq-client/pom.xml b/activemq-client/pom.xml
index 56dfdd911f1..6e41124eba9 100644
--- a/activemq-client/pom.xml
+++ b/activemq-client/pom.xml
@@ -79,6 +79,11 @@
log4j-slf4j2-impl
test
+
+ org.javassist
+ javassist
+ test
+
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java
index 0b6816029cb..86171dc288f 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java
@@ -48,7 +48,7 @@ public final class OpenWireFormat implements WireFormat {
private static final int MARSHAL_CACHE_SIZE = Short.MAX_VALUE / 2;
private static final int MARSHAL_CACHE_FREE_SPACE = 100;
- private DataStreamMarshaller dataMarshallers[];
+ private DataStreamMarshaller[] dataMarshallers;
private int version;
private boolean stackTraceEnabled;
private boolean tcpNoDelayEnabled;
@@ -61,13 +61,22 @@ public final class OpenWireFormat implements WireFormat {
// The following fields are used for value caching
private short nextMarshallCacheIndex;
private short nextMarshallCacheEvictionIndex;
- private Map marshallCacheMap = new HashMap();
+ private Map marshallCacheMap = new HashMap<>();
private DataStructure marshallCache[] = null;
private DataStructure unmarshallCache[] = null;
- private DataByteArrayOutputStream bytesOut = new DataByteArrayOutputStream();
- private DataByteArrayInputStream bytesIn = new DataByteArrayInputStream();
+ private final DataByteArrayOutputStream bytesOut = new DataByteArrayOutputStream();
+ private final DataByteArrayInputStream bytesIn = new DataByteArrayInputStream();
private WireFormatInfo preferedWireFormatInfo;
+ // Used to track the currentFrameSize for validation during unmarshalling
+ // Ideally we would pass the MarshallingContext directly to the marshalling methods,
+ // however this would require modifying the DataStreamMarshaller interface which would result
+ // in hundreds of existing methods having to be updated so this allows avoiding that and
+ // tracking the state without breaking the existing API.
+ // Note that while this is currently only used during unmarshalling, but if necessary could
+ // be extended in the future to be used during marshalling as well.
+ private final ThreadLocal marshallingContext = new ThreadLocal<>();
+
public OpenWireFormat() {
this(DEFAULT_STORE_VERSION);
}
@@ -191,26 +200,23 @@ public synchronized ByteSequence marshal(Object command) throws IOException {
@Override
public synchronized Object unmarshal(ByteSequence sequence) throws IOException {
bytesIn.restart(sequence);
- // DataInputStream dis = new DataInputStream(new
- // ByteArrayInputStream(sequence));
-
- if (!sizePrefixDisabled) {
- int size = bytesIn.readInt();
- if (sequence.getLength() - 4 != size) {
- // throw new IOException("Packet size does not match marshaled
- // size");
- }
- if (maxFrameSizeEnabled && size > maxFrameSize) {
- throw IOExceptionSupport.createFrameSizeException(size, maxFrameSize);
+ try {
+ final var context = new MarshallingContext();
+ marshallingContext.set(context);
+
+ if (!sizePrefixDisabled) {
+ int size = bytesIn.readInt();
+ if (maxFrameSizeEnabled && size > maxFrameSize) {
+ throw IOExceptionSupport.createFrameSizeException(size, maxFrameSize);
+ }
+ context.setFrameSize(size);
}
+ return doUnmarshal(bytesIn);
+ } finally {
+ // After we unmarshal we can clear the context
+ marshallingContext.remove();
}
-
- Object command = doUnmarshal(bytesIn);
- // if( !cacheEnabled && ((DataStructure)command).isMarshallAware() ) {
- // ((MarshallAware) command).setCachedMarshalledForm(this, sequence);
- // }
- return command;
}
@Override
@@ -275,19 +281,22 @@ public synchronized void marshal(Object o, DataOutput dataOut) throws IOExceptio
@Override
public Object unmarshal(DataInput dis) throws IOException {
- DataInput dataIn = dis;
- if (!sizePrefixDisabled) {
- int size = dis.readInt();
- if (maxFrameSizeEnabled && size > maxFrameSize) {
- throw IOExceptionSupport.createFrameSizeException(size, maxFrameSize);
+ try {
+ final var context = new MarshallingContext();
+ marshallingContext.set(context);
+
+ if (!sizePrefixDisabled) {
+ int size = dis.readInt();
+ if (maxFrameSizeEnabled && size > maxFrameSize) {
+ throw IOExceptionSupport.createFrameSizeException(size, maxFrameSize);
+ }
+ context.setFrameSize(size);
}
- // int size = dis.readInt();
- // byte[] data = new byte[size];
- // dis.readFully(data);
- // bytesIn.restart(data);
- // dataIn = bytesIn;
+ return doUnmarshal(dis);
+ } finally {
+ // After we unmarshal we can clear
+ marshallingContext.remove();
}
- return doUnmarshal(dataIn);
}
/**
@@ -363,7 +372,7 @@ public void setVersion(int version) {
this.version = version;
}
- public Object doUnmarshal(DataInput dis) throws IOException {
+ private Object doUnmarshal(DataInput dis) throws IOException {
byte dataType = dis.readByte();
if (dataType != NULL_TYPE) {
DataStreamMarshaller dsm = dataMarshallers[dataType & 0xFF];
@@ -698,4 +707,47 @@ protected long min(long version1, long version2) {
}
return version2;
}
+
+ MarshallingContext getMarshallingContext() {
+ return marshallingContext.get();
+ }
+
+ // Used to track the estimated allocated buffer sizes to validate
+ // against the current frame being processed
+ static class MarshallingContext {
+ // Use primitives to minimize memory footprint
+ private int frameSize = -1;
+ private int estimatedAllocated = 0;
+
+ void setFrameSize(int frameSize) throws IOException {
+ this.frameSize = frameSize;
+ if (frameSize < 0) {
+ throw error("Frame size " + frameSize + " can't be negative.");
+ }
+ }
+
+ void increment(int size) throws IOException {
+ if (size < 0) {
+ throw error("Size " + size + " can't be negative.");
+ }
+ try {
+ estimatedAllocated = Math.addExact(estimatedAllocated, size);
+ } catch (ArithmeticException e) {
+ throw error("Buffer overflow when incrementing size value: " + size);
+ }
+ }
+
+ public int getFrameSize() {
+ return frameSize;
+ }
+
+ public int getEstimatedAllocated() {
+ return estimatedAllocated;
+ }
+
+ private static IOException error(String errorMessage) {
+ return new IOException(new IllegalArgumentException(errorMessage));
+ }
+ }
+
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireUtil.java b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireUtil.java
index 9d02744265f..234cee43e38 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireUtil.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireUtil.java
@@ -16,10 +16,13 @@
*/
package org.apache.activemq.openwire;
+import java.io.IOException;
+import org.apache.activemq.util.IOExceptionSupport;
+
public class OpenWireUtil {
- private static final String jmsPackageToReplace = "javax.jms";
- private static final String jmsPackageToUse = "jakarta.jms";
+ static final String jmsPackageToReplace = "javax.jms";
+ static final String jmsPackageToUse = "jakarta.jms";
/**
* Verify that the provided class extends {@link Throwable} and throw an
@@ -33,6 +36,50 @@ public static void validateIsThrowable(Class> clazz) {
}
}
+ /**
+ * Verify that the buffer size that will be allocated will not push the total allocated
+ * size of this frame above the expected frame size. This is an estimate as the current
+ * size is only tracked when calls to this method are made and is primarily intended
+ * to prevent large arrays from being created due to an invalid size.
+ *
+ * Also verify the size against configured max frame size.
+ * This check is a sanity check in case of corrupt packets contain invalid size values.
+ *
+ * @param wireFormat configured OpenWireFormat
+ * @param size buffer size to verify
+ * @throws IOException If size is larger than currentFrameSize or maxFrameSize
+ */
+ public static void validateBufferSize(OpenWireFormat wireFormat, int size) throws IOException {
+ validateLessThanFrameSize(wireFormat, size);
+
+ // if currentFrameSize is set and was checked above then this check should not be needed,
+ // but it doesn't hurt to verify again in case the max frame size check was missed
+ // somehow
+ if (wireFormat.isMaxFrameSizeEnabled() && size > wireFormat.getMaxFrameSize()) {
+ throw IOExceptionSupport.createFrameSizeException(size, wireFormat.getMaxFrameSize());
+ }
+ }
+
+ // Verify total tracked sizes will not exceed the overall size of the frame
+ private static void validateLessThanFrameSize(OpenWireFormat wireFormat, int size)
+ throws IOException {
+ final var context = wireFormat.getMarshallingContext();
+ // No information on current frame size so just return
+ if (context == null || context.getFrameSize() < 0) {
+ return;
+ }
+
+ // Increment existing estimated buffer size with new size
+ context.increment(size);
+
+ // We should never be trying to allocate a buffer that is going to push the total
+ // size greater than the entire frame itself
+ if (context.getEstimatedAllocated() > context.getFrameSize()) {
+ throw IOExceptionSupport.createFrameSizeBufferException(
+ context.getEstimatedAllocated(), context.getFrameSize());
+ }
+ }
+
/**
* This method can be used to convert from javax -> jakarta or
* vice versa depending on the version used by the client
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java
index cd22f666342..c35188260ef 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java
@@ -411,10 +411,11 @@ protected void tightMarshalByteArray2(byte[] data, DataOutput dataOut, BooleanSt
}
}
- protected byte[] tightUnmarshalByteArray(DataInput dataIn, BooleanStream bs) throws IOException {
+ protected byte[] tightUnmarshalByteArray(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) throws IOException {
byte rc[] = null;
if (bs.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
rc = new byte[size];
dataIn.readFully(rc);
}
@@ -438,10 +439,11 @@ protected void tightMarshalByteSequence2(ByteSequence data, DataOutput dataOut,
}
}
- protected ByteSequence tightUnmarshalByteSequence(DataInput dataIn, BooleanStream bs) throws IOException {
+ protected ByteSequence tightUnmarshalByteSequence(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) throws IOException {
ByteSequence rc = null;
if (bs.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
byte[] t = new byte[size];
dataIn.readFully(t);
return new ByteSequence(t, 0, size);
@@ -618,10 +620,11 @@ protected void looseMarshalByteArray(OpenWireFormat wireFormat, byte[] data, Dat
}
}
- protected byte[] looseUnmarshalByteArray(DataInput dataIn) throws IOException {
+ protected byte[] looseUnmarshalByteArray(OpenWireFormat wireFormat, DataInput dataIn) throws IOException {
byte rc[] = null;
if (dataIn.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
rc = new byte[size];
dataIn.readFully(rc);
}
@@ -637,10 +640,11 @@ protected void looseMarshalByteSequence(OpenWireFormat wireFormat, ByteSequence
}
}
- protected ByteSequence looseUnmarshalByteSequence(DataInput dataIn) throws IOException {
+ protected ByteSequence looseUnmarshalByteSequence(OpenWireFormat wireFormat, DataInput dataIn) throws IOException {
ByteSequence rc = null;
if (dataIn.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
byte[] t = new byte[size];
dataIn.readFully(t);
rc = new ByteSequence(t, 0, size);
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v1/MessageMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v1/MessageMarshaller.java
index dd41daf6a54..bd81a8c00fd 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v1/MessageMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v1/MessageMarshaller.java
@@ -65,8 +65,8 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setReplyTo((org.apache.activemq.command.ActiveMQDestination)tightUnmarsalNestedObject(wireFormat, dataIn, bs));
info.setTimestamp(tightUnmarshalLong(wireFormat, dataIn, bs));
info.setType(tightUnmarshalString(dataIn, bs));
- info.setContent(tightUnmarshalByteSequence(dataIn, bs));
- info.setMarshalledProperties(tightUnmarshalByteSequence(dataIn, bs));
+ info.setContent(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
+ info.setMarshalledProperties(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
info.setDataStructure((org.apache.activemq.command.DataStructure)tightUnmarsalNestedObject(wireFormat, dataIn, bs));
info.setTargetConsumerId((org.apache.activemq.command.ConsumerId)tightUnmarsalCachedObject(wireFormat, dataIn, bs));
info.setCompressed(bs.readBoolean());
@@ -196,8 +196,8 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setReplyTo((org.apache.activemq.command.ActiveMQDestination)looseUnmarsalNestedObject(wireFormat, dataIn));
info.setTimestamp(looseUnmarshalLong(wireFormat, dataIn));
info.setType(looseUnmarshalString(dataIn));
- info.setContent(looseUnmarshalByteSequence(dataIn));
- info.setMarshalledProperties(looseUnmarshalByteSequence(dataIn));
+ info.setContent(looseUnmarshalByteSequence(wireFormat, dataIn));
+ info.setMarshalledProperties(looseUnmarshalByteSequence(wireFormat, dataIn));
info.setDataStructure((org.apache.activemq.command.DataStructure)looseUnmarsalNestedObject(wireFormat, dataIn));
info.setTargetConsumerId((org.apache.activemq.command.ConsumerId)looseUnmarsalCachedObject(wireFormat, dataIn));
info.setCompressed(dataIn.readBoolean());
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v1/PartialCommandMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v1/PartialCommandMarshaller.java
index 9ead0edd5f4..6b317d4f7a2 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v1/PartialCommandMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v1/PartialCommandMarshaller.java
@@ -68,7 +68,7 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
PartialCommand info = (PartialCommand)o;
info.setCommandId(dataIn.readInt());
- info.setData(tightUnmarshalByteArray(dataIn, bs));
+ info.setData(tightUnmarshalByteArray(wireFormat, dataIn, bs));
}
@@ -114,7 +114,7 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
PartialCommand info = (PartialCommand)o;
info.setCommandId(dataIn.readInt());
- info.setData(looseUnmarshalByteArray(dataIn));
+ info.setData(looseUnmarshalByteArray(wireFormat, dataIn));
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v1/WireFormatInfoMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v1/WireFormatInfoMarshaller.java
index fa939998d58..1e1544a8f68 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v1/WireFormatInfoMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v1/WireFormatInfoMarshaller.java
@@ -72,7 +72,7 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setMagic(tightUnmarshalConstByteArray(dataIn, bs, 8));
info.setVersion(dataIn.readInt());
- info.setMarshalledProperties(tightUnmarshalByteSequence(dataIn, bs));
+ info.setMarshalledProperties(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
info.afterUnmarshall(wireFormat);
@@ -130,7 +130,7 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setMagic(looseUnmarshalConstByteArray(dataIn, 8));
info.setVersion(dataIn.readInt());
- info.setMarshalledProperties(looseUnmarshalByteSequence(dataIn));
+ info.setMarshalledProperties(looseUnmarshalByteSequence(wireFormat, dataIn));
info.afterUnmarshall(wireFormat);
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v1/XATransactionIdMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v1/XATransactionIdMarshaller.java
index 7ac532ce939..438cd1a05a8 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v1/XATransactionIdMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v1/XATransactionIdMarshaller.java
@@ -68,8 +68,8 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
XATransactionId info = (XATransactionId)o;
info.setFormatId(dataIn.readInt());
- info.setGlobalTransactionId(tightUnmarshalByteArray(dataIn, bs));
- info.setBranchQualifier(tightUnmarshalByteArray(dataIn, bs));
+ info.setGlobalTransactionId(tightUnmarshalByteArray(wireFormat, dataIn, bs));
+ info.setBranchQualifier(tightUnmarshalByteArray(wireFormat, dataIn, bs));
}
@@ -117,8 +117,8 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
XATransactionId info = (XATransactionId)o;
info.setFormatId(dataIn.readInt());
- info.setGlobalTransactionId(looseUnmarshalByteArray(dataIn));
- info.setBranchQualifier(looseUnmarshalByteArray(dataIn));
+ info.setGlobalTransactionId(looseUnmarshalByteArray(wireFormat, dataIn));
+ info.setBranchQualifier(looseUnmarshalByteArray(wireFormat, dataIn));
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshaller.java
index 7bdfbb81649..106f308f390 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshaller.java
@@ -410,10 +410,11 @@ protected void tightMarshalByteArray2(byte[] data, DataOutput dataOut, BooleanSt
}
}
- protected byte[] tightUnmarshalByteArray(DataInput dataIn, BooleanStream bs) throws IOException {
+ protected byte[] tightUnmarshalByteArray(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) throws IOException {
byte rc[] = null;
if (bs.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
rc = new byte[size];
dataIn.readFully(rc);
}
@@ -437,10 +438,11 @@ protected void tightMarshalByteSequence2(ByteSequence data, DataOutput dataOut,
}
}
- protected ByteSequence tightUnmarshalByteSequence(DataInput dataIn, BooleanStream bs) throws IOException {
+ protected ByteSequence tightUnmarshalByteSequence(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) throws IOException {
ByteSequence rc = null;
if (bs.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
byte[] t = new byte[size];
dataIn.readFully(t);
return new ByteSequence(t, 0, size);
@@ -617,10 +619,11 @@ protected void looseMarshalByteArray(OpenWireFormat wireFormat, byte[] data, Dat
}
}
- protected byte[] looseUnmarshalByteArray(DataInput dataIn) throws IOException {
+ protected byte[] looseUnmarshalByteArray(OpenWireFormat wireFormat, DataInput dataIn) throws IOException {
byte rc[] = null;
if (dataIn.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
rc = new byte[size];
dataIn.readFully(rc);
}
@@ -636,10 +639,11 @@ protected void looseMarshalByteSequence(OpenWireFormat wireFormat, ByteSequence
}
}
- protected ByteSequence looseUnmarshalByteSequence(DataInput dataIn) throws IOException {
+ protected ByteSequence looseUnmarshalByteSequence(OpenWireFormat wireFormat, DataInput dataIn) throws IOException {
ByteSequence rc = null;
if (dataIn.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
byte[] t = new byte[size];
dataIn.readFully(t);
rc = new ByteSequence(t, 0, size);
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/ConnectionControlMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/ConnectionControlMarshaller.java
index 88be6bbe0c6..b851e7fba12 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/ConnectionControlMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/ConnectionControlMarshaller.java
@@ -74,7 +74,7 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setConnectedBrokers(tightUnmarshalString(dataIn, bs));
info.setReconnectTo(tightUnmarshalString(dataIn, bs));
info.setRebalanceConnection(bs.readBoolean());
- info.setToken(tightUnmarshalByteArray(dataIn, bs));
+ info.setToken(tightUnmarshalByteArray(wireFormat, dataIn, bs));
}
@@ -142,7 +142,7 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setConnectedBrokers(looseUnmarshalString(dataIn));
info.setReconnectTo(looseUnmarshalString(dataIn));
info.setRebalanceConnection(dataIn.readBoolean());
- info.setToken(looseUnmarshalByteArray(dataIn));
+ info.setToken(looseUnmarshalByteArray(wireFormat, dataIn));
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/MessageMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/MessageMarshaller.java
index 262faffd78e..3d4957f5ccc 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/MessageMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/MessageMarshaller.java
@@ -69,8 +69,8 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setReplyTo((org.apache.activemq.command.ActiveMQDestination) tightUnmarsalNestedObject(wireFormat, dataIn, bs));
info.setTimestamp(tightUnmarshalLong(wireFormat, dataIn, bs));
info.setType(tightUnmarshalString(dataIn, bs));
- info.setContent(tightUnmarshalByteSequence(dataIn, bs));
- info.setMarshalledProperties(tightUnmarshalByteSequence(dataIn, bs));
+ info.setContent(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
+ info.setMarshalledProperties(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
info.setDataStructure((org.apache.activemq.command.DataStructure) tightUnmarsalNestedObject(wireFormat, dataIn, bs));
info.setTargetConsumerId((org.apache.activemq.command.ConsumerId) tightUnmarsalCachedObject(wireFormat, dataIn, bs));
info.setCompressed(bs.readBoolean());
@@ -228,8 +228,8 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setReplyTo((org.apache.activemq.command.ActiveMQDestination) looseUnmarsalNestedObject(wireFormat, dataIn));
info.setTimestamp(looseUnmarshalLong(wireFormat, dataIn));
info.setType(looseUnmarshalString(dataIn));
- info.setContent(looseUnmarshalByteSequence(dataIn));
- info.setMarshalledProperties(looseUnmarshalByteSequence(dataIn));
+ info.setContent(looseUnmarshalByteSequence(wireFormat, dataIn));
+ info.setMarshalledProperties(looseUnmarshalByteSequence(wireFormat, dataIn));
info.setDataStructure((org.apache.activemq.command.DataStructure) looseUnmarsalNestedObject(wireFormat, dataIn));
info.setTargetConsumerId((org.apache.activemq.command.ConsumerId) looseUnmarsalCachedObject(wireFormat, dataIn));
info.setCompressed(dataIn.readBoolean());
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/PartialCommandMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/PartialCommandMarshaller.java
index 935acfff922..4a9fb290577 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/PartialCommandMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/PartialCommandMarshaller.java
@@ -67,7 +67,7 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
PartialCommand info = (PartialCommand)o;
info.setCommandId(dataIn.readInt());
- info.setData(tightUnmarshalByteArray(dataIn, bs));
+ info.setData(tightUnmarshalByteArray(wireFormat, dataIn, bs));
}
@@ -113,7 +113,7 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
PartialCommand info = (PartialCommand)o;
info.setCommandId(dataIn.readInt());
- info.setData(looseUnmarshalByteArray(dataIn));
+ info.setData(looseUnmarshalByteArray(wireFormat, dataIn));
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/WireFormatInfoMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/WireFormatInfoMarshaller.java
index 2d2ce4f9d1f..d164e1c5ae1 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/WireFormatInfoMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/WireFormatInfoMarshaller.java
@@ -71,7 +71,7 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setMagic(tightUnmarshalConstByteArray(dataIn, bs, 8));
info.setVersion(dataIn.readInt());
- info.setMarshalledProperties(tightUnmarshalByteSequence(dataIn, bs));
+ info.setMarshalledProperties(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
info.afterUnmarshall(wireFormat);
@@ -129,7 +129,7 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setMagic(looseUnmarshalConstByteArray(dataIn, 8));
info.setVersion(dataIn.readInt());
- info.setMarshalledProperties(looseUnmarshalByteSequence(dataIn));
+ info.setMarshalledProperties(looseUnmarshalByteSequence(wireFormat, dataIn));
info.afterUnmarshall(wireFormat);
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/XATransactionIdMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/XATransactionIdMarshaller.java
index fa2aae287c7..cde7def8ef5 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/XATransactionIdMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/XATransactionIdMarshaller.java
@@ -67,8 +67,8 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
XATransactionId info = (XATransactionId)o;
info.setFormatId(dataIn.readInt());
- info.setGlobalTransactionId(tightUnmarshalByteArray(dataIn, bs));
- info.setBranchQualifier(tightUnmarshalByteArray(dataIn, bs));
+ info.setGlobalTransactionId(tightUnmarshalByteArray(wireFormat, dataIn, bs));
+ info.setBranchQualifier(tightUnmarshalByteArray(wireFormat, dataIn, bs));
}
@@ -116,8 +116,8 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
XATransactionId info = (XATransactionId)o;
info.setFormatId(dataIn.readInt());
- info.setGlobalTransactionId(looseUnmarshalByteArray(dataIn));
- info.setBranchQualifier(looseUnmarshalByteArray(dataIn));
+ info.setGlobalTransactionId(looseUnmarshalByteArray(wireFormat, dataIn));
+ info.setBranchQualifier(looseUnmarshalByteArray(wireFormat, dataIn));
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v11/BaseDataStreamMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v11/BaseDataStreamMarshaller.java
index 67ef744f1ab..b12be930cfc 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v11/BaseDataStreamMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v11/BaseDataStreamMarshaller.java
@@ -409,10 +409,11 @@ protected void tightMarshalByteArray2(byte[] data, DataOutput dataOut, BooleanSt
}
}
- protected byte[] tightUnmarshalByteArray(DataInput dataIn, BooleanStream bs) throws IOException {
+ protected byte[] tightUnmarshalByteArray(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) throws IOException {
byte rc[] = null;
if (bs.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
rc = new byte[size];
dataIn.readFully(rc);
}
@@ -436,10 +437,11 @@ protected void tightMarshalByteSequence2(ByteSequence data, DataOutput dataOut,
}
}
- protected ByteSequence tightUnmarshalByteSequence(DataInput dataIn, BooleanStream bs) throws IOException {
+ protected ByteSequence tightUnmarshalByteSequence(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) throws IOException {
ByteSequence rc = null;
if (bs.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
byte[] t = new byte[size];
dataIn.readFully(t);
return new ByteSequence(t, 0, size);
@@ -616,10 +618,11 @@ protected void looseMarshalByteArray(OpenWireFormat wireFormat, byte[] data, Dat
}
}
- protected byte[] looseUnmarshalByteArray(DataInput dataIn) throws IOException {
+ protected byte[] looseUnmarshalByteArray(OpenWireFormat wireFormat, DataInput dataIn) throws IOException {
byte rc[] = null;
if (dataIn.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
rc = new byte[size];
dataIn.readFully(rc);
}
@@ -635,10 +638,11 @@ protected void looseMarshalByteSequence(OpenWireFormat wireFormat, ByteSequence
}
}
- protected ByteSequence looseUnmarshalByteSequence(DataInput dataIn) throws IOException {
+ protected ByteSequence looseUnmarshalByteSequence(OpenWireFormat wireFormat, DataInput dataIn) throws IOException {
ByteSequence rc = null;
if (dataIn.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
byte[] t = new byte[size];
dataIn.readFully(t);
rc = new ByteSequence(t, 0, size);
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v11/ConnectionControlMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v11/ConnectionControlMarshaller.java
index 2a5a0cc0c5d..23563eddd2a 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v11/ConnectionControlMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v11/ConnectionControlMarshaller.java
@@ -74,7 +74,7 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setConnectedBrokers(tightUnmarshalString(dataIn, bs));
info.setReconnectTo(tightUnmarshalString(dataIn, bs));
info.setRebalanceConnection(bs.readBoolean());
- info.setToken(tightUnmarshalByteArray(dataIn, bs));
+ info.setToken(tightUnmarshalByteArray(wireFormat, dataIn, bs));
}
@@ -142,7 +142,7 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setConnectedBrokers(looseUnmarshalString(dataIn));
info.setReconnectTo(looseUnmarshalString(dataIn));
info.setRebalanceConnection(dataIn.readBoolean());
- info.setToken(looseUnmarshalByteArray(dataIn));
+ info.setToken(looseUnmarshalByteArray(wireFormat, dataIn));
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v11/MessageMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v11/MessageMarshaller.java
index 54a99423d14..e906955771f 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v11/MessageMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v11/MessageMarshaller.java
@@ -69,8 +69,8 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setReplyTo((org.apache.activemq.command.ActiveMQDestination) tightUnmarsalNestedObject(wireFormat, dataIn, bs));
info.setTimestamp(tightUnmarshalLong(wireFormat, dataIn, bs));
info.setType(tightUnmarshalString(dataIn, bs));
- info.setContent(tightUnmarshalByteSequence(dataIn, bs));
- info.setMarshalledProperties(tightUnmarshalByteSequence(dataIn, bs));
+ info.setContent(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
+ info.setMarshalledProperties(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
info.setDataStructure((org.apache.activemq.command.DataStructure) tightUnmarsalNestedObject(wireFormat, dataIn, bs));
info.setTargetConsumerId((org.apache.activemq.command.ConsumerId) tightUnmarsalCachedObject(wireFormat, dataIn, bs));
info.setCompressed(bs.readBoolean());
@@ -228,8 +228,8 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setReplyTo((org.apache.activemq.command.ActiveMQDestination) looseUnmarsalNestedObject(wireFormat, dataIn));
info.setTimestamp(looseUnmarshalLong(wireFormat, dataIn));
info.setType(looseUnmarshalString(dataIn));
- info.setContent(looseUnmarshalByteSequence(dataIn));
- info.setMarshalledProperties(looseUnmarshalByteSequence(dataIn));
+ info.setContent(looseUnmarshalByteSequence(wireFormat, dataIn));
+ info.setMarshalledProperties(looseUnmarshalByteSequence(wireFormat, dataIn));
info.setDataStructure((org.apache.activemq.command.DataStructure) looseUnmarsalNestedObject(wireFormat, dataIn));
info.setTargetConsumerId((org.apache.activemq.command.ConsumerId) looseUnmarsalCachedObject(wireFormat, dataIn));
info.setCompressed(dataIn.readBoolean());
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v11/PartialCommandMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v11/PartialCommandMarshaller.java
index db480e1ba49..4e5d17ebe96 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v11/PartialCommandMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v11/PartialCommandMarshaller.java
@@ -67,7 +67,7 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
PartialCommand info = (PartialCommand)o;
info.setCommandId(dataIn.readInt());
- info.setData(tightUnmarshalByteArray(dataIn, bs));
+ info.setData(tightUnmarshalByteArray(wireFormat, dataIn, bs));
}
@@ -113,7 +113,7 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
PartialCommand info = (PartialCommand)o;
info.setCommandId(dataIn.readInt());
- info.setData(looseUnmarshalByteArray(dataIn));
+ info.setData(looseUnmarshalByteArray(wireFormat, dataIn));
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v11/WireFormatInfoMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v11/WireFormatInfoMarshaller.java
index ef5e569fd5e..0d5a893bc23 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v11/WireFormatInfoMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v11/WireFormatInfoMarshaller.java
@@ -71,7 +71,7 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setMagic(tightUnmarshalConstByteArray(dataIn, bs, 8));
info.setVersion(dataIn.readInt());
- info.setMarshalledProperties(tightUnmarshalByteSequence(dataIn, bs));
+ info.setMarshalledProperties(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
info.afterUnmarshall(wireFormat);
@@ -129,7 +129,7 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setMagic(looseUnmarshalConstByteArray(dataIn, 8));
info.setVersion(dataIn.readInt());
- info.setMarshalledProperties(looseUnmarshalByteSequence(dataIn));
+ info.setMarshalledProperties(looseUnmarshalByteSequence(wireFormat, dataIn));
info.afterUnmarshall(wireFormat);
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v11/XATransactionIdMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v11/XATransactionIdMarshaller.java
index ee4b5ecd35b..bc9d311d3cb 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v11/XATransactionIdMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v11/XATransactionIdMarshaller.java
@@ -67,8 +67,8 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
XATransactionId info = (XATransactionId)o;
info.setFormatId(dataIn.readInt());
- info.setGlobalTransactionId(tightUnmarshalByteArray(dataIn, bs));
- info.setBranchQualifier(tightUnmarshalByteArray(dataIn, bs));
+ info.setGlobalTransactionId(tightUnmarshalByteArray(wireFormat, dataIn, bs));
+ info.setBranchQualifier(tightUnmarshalByteArray(wireFormat, dataIn, bs));
}
@@ -116,8 +116,8 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
XATransactionId info = (XATransactionId)o;
info.setFormatId(dataIn.readInt());
- info.setGlobalTransactionId(looseUnmarshalByteArray(dataIn));
- info.setBranchQualifier(looseUnmarshalByteArray(dataIn));
+ info.setGlobalTransactionId(looseUnmarshalByteArray(wireFormat, dataIn));
+ info.setBranchQualifier(looseUnmarshalByteArray(wireFormat, dataIn));
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v12/BaseDataStreamMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v12/BaseDataStreamMarshaller.java
index 7c59753d370..41f693b810b 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v12/BaseDataStreamMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v12/BaseDataStreamMarshaller.java
@@ -412,10 +412,11 @@ protected void tightMarshalByteArray2(byte[] data, DataOutput dataOut, BooleanSt
}
}
- protected byte[] tightUnmarshalByteArray(DataInput dataIn, BooleanStream bs) throws IOException {
+ protected byte[] tightUnmarshalByteArray(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) throws IOException {
byte rc[] = null;
if (bs.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
rc = new byte[size];
dataIn.readFully(rc);
}
@@ -439,10 +440,11 @@ protected void tightMarshalByteSequence2(ByteSequence data, DataOutput dataOut,
}
}
- protected ByteSequence tightUnmarshalByteSequence(DataInput dataIn, BooleanStream bs) throws IOException {
+ protected ByteSequence tightUnmarshalByteSequence(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) throws IOException {
ByteSequence rc = null;
if (bs.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
byte[] t = new byte[size];
dataIn.readFully(t);
return new ByteSequence(t, 0, size);
@@ -619,10 +621,11 @@ protected void looseMarshalByteArray(OpenWireFormat wireFormat, byte[] data, Dat
}
}
- protected byte[] looseUnmarshalByteArray(DataInput dataIn) throws IOException {
+ protected byte[] looseUnmarshalByteArray(OpenWireFormat wireFormat, DataInput dataIn) throws IOException {
byte rc[] = null;
if (dataIn.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
rc = new byte[size];
dataIn.readFully(rc);
}
@@ -638,10 +641,11 @@ protected void looseMarshalByteSequence(OpenWireFormat wireFormat, ByteSequence
}
}
- protected ByteSequence looseUnmarshalByteSequence(DataInput dataIn) throws IOException {
+ protected ByteSequence looseUnmarshalByteSequence(OpenWireFormat wireFormat, DataInput dataIn) throws IOException {
ByteSequence rc = null;
if (dataIn.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
byte[] t = new byte[size];
dataIn.readFully(t);
rc = new ByteSequence(t, 0, size);
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v12/ConnectionControlMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v12/ConnectionControlMarshaller.java
index 1f15ffc0352..c687c261bf7 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v12/ConnectionControlMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v12/ConnectionControlMarshaller.java
@@ -74,7 +74,7 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setConnectedBrokers(tightUnmarshalString(dataIn, bs));
info.setReconnectTo(tightUnmarshalString(dataIn, bs));
info.setRebalanceConnection(bs.readBoolean());
- info.setToken(tightUnmarshalByteArray(dataIn, bs));
+ info.setToken(tightUnmarshalByteArray(wireFormat, dataIn, bs));
}
@@ -142,7 +142,7 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setConnectedBrokers(looseUnmarshalString(dataIn));
info.setReconnectTo(looseUnmarshalString(dataIn));
info.setRebalanceConnection(dataIn.readBoolean());
- info.setToken(looseUnmarshalByteArray(dataIn));
+ info.setToken(looseUnmarshalByteArray(wireFormat, dataIn));
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v12/MessageMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v12/MessageMarshaller.java
index 0f903a1662e..d87e49a57a1 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v12/MessageMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v12/MessageMarshaller.java
@@ -69,8 +69,8 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setReplyTo((org.apache.activemq.command.ActiveMQDestination) tightUnmarsalNestedObject(wireFormat, dataIn, bs));
info.setTimestamp(tightUnmarshalLong(wireFormat, dataIn, bs));
info.setType(tightUnmarshalString(dataIn, bs));
- info.setContent(tightUnmarshalByteSequence(dataIn, bs));
- info.setMarshalledProperties(tightUnmarshalByteSequence(dataIn, bs));
+ info.setContent(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
+ info.setMarshalledProperties(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
info.setDataStructure((org.apache.activemq.command.DataStructure) tightUnmarsalNestedObject(wireFormat, dataIn, bs));
info.setTargetConsumerId((org.apache.activemq.command.ConsumerId) tightUnmarsalCachedObject(wireFormat, dataIn, bs));
info.setCompressed(bs.readBoolean());
@@ -228,8 +228,8 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setReplyTo((org.apache.activemq.command.ActiveMQDestination) looseUnmarsalNestedObject(wireFormat, dataIn));
info.setTimestamp(looseUnmarshalLong(wireFormat, dataIn));
info.setType(looseUnmarshalString(dataIn));
- info.setContent(looseUnmarshalByteSequence(dataIn));
- info.setMarshalledProperties(looseUnmarshalByteSequence(dataIn));
+ info.setContent(looseUnmarshalByteSequence(wireFormat, dataIn));
+ info.setMarshalledProperties(looseUnmarshalByteSequence(wireFormat, dataIn));
info.setDataStructure((org.apache.activemq.command.DataStructure) looseUnmarsalNestedObject(wireFormat, dataIn));
info.setTargetConsumerId((org.apache.activemq.command.ConsumerId) looseUnmarsalCachedObject(wireFormat, dataIn));
info.setCompressed(dataIn.readBoolean());
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v12/PartialCommandMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v12/PartialCommandMarshaller.java
index b816d8a7946..6fc32d57ec9 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v12/PartialCommandMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v12/PartialCommandMarshaller.java
@@ -67,7 +67,7 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
PartialCommand info = (PartialCommand)o;
info.setCommandId(dataIn.readInt());
- info.setData(tightUnmarshalByteArray(dataIn, bs));
+ info.setData(tightUnmarshalByteArray(wireFormat, dataIn, bs));
}
@@ -113,7 +113,7 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
PartialCommand info = (PartialCommand)o;
info.setCommandId(dataIn.readInt());
- info.setData(looseUnmarshalByteArray(dataIn));
+ info.setData(looseUnmarshalByteArray(wireFormat, dataIn));
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v12/WireFormatInfoMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v12/WireFormatInfoMarshaller.java
index f284dd5d859..a77e010733c 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v12/WireFormatInfoMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v12/WireFormatInfoMarshaller.java
@@ -71,7 +71,7 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setMagic(tightUnmarshalConstByteArray(dataIn, bs, 8));
info.setVersion(dataIn.readInt());
- info.setMarshalledProperties(tightUnmarshalByteSequence(dataIn, bs));
+ info.setMarshalledProperties(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
info.afterUnmarshall(wireFormat);
@@ -129,7 +129,7 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setMagic(looseUnmarshalConstByteArray(dataIn, 8));
info.setVersion(dataIn.readInt());
- info.setMarshalledProperties(looseUnmarshalByteSequence(dataIn));
+ info.setMarshalledProperties(looseUnmarshalByteSequence(wireFormat, dataIn));
info.afterUnmarshall(wireFormat);
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v12/XATransactionIdMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v12/XATransactionIdMarshaller.java
index e25c5f33f54..ea3490cf8c8 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v12/XATransactionIdMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v12/XATransactionIdMarshaller.java
@@ -67,8 +67,8 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
XATransactionId info = (XATransactionId)o;
info.setFormatId(dataIn.readInt());
- info.setGlobalTransactionId(tightUnmarshalByteArray(dataIn, bs));
- info.setBranchQualifier(tightUnmarshalByteArray(dataIn, bs));
+ info.setGlobalTransactionId(tightUnmarshalByteArray(wireFormat, dataIn, bs));
+ info.setBranchQualifier(tightUnmarshalByteArray(wireFormat, dataIn, bs));
}
@@ -116,8 +116,8 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
XATransactionId info = (XATransactionId)o;
info.setFormatId(dataIn.readInt());
- info.setGlobalTransactionId(looseUnmarshalByteArray(dataIn));
- info.setBranchQualifier(looseUnmarshalByteArray(dataIn));
+ info.setGlobalTransactionId(looseUnmarshalByteArray(wireFormat, dataIn));
+ info.setBranchQualifier(looseUnmarshalByteArray(wireFormat, dataIn));
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v9/BaseDataStreamMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v9/BaseDataStreamMarshaller.java
index 13dfae871bc..cef5091da4a 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v9/BaseDataStreamMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v9/BaseDataStreamMarshaller.java
@@ -409,10 +409,11 @@ protected void tightMarshalByteArray2(byte[] data, DataOutput dataOut, BooleanSt
}
}
- protected byte[] tightUnmarshalByteArray(DataInput dataIn, BooleanStream bs) throws IOException {
+ protected byte[] tightUnmarshalByteArray(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) throws IOException {
byte rc[] = null;
if (bs.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
rc = new byte[size];
dataIn.readFully(rc);
}
@@ -436,10 +437,11 @@ protected void tightMarshalByteSequence2(ByteSequence data, DataOutput dataOut,
}
}
- protected ByteSequence tightUnmarshalByteSequence(DataInput dataIn, BooleanStream bs) throws IOException {
+ protected ByteSequence tightUnmarshalByteSequence(OpenWireFormat wireFormat, DataInput dataIn, BooleanStream bs) throws IOException {
ByteSequence rc = null;
if (bs.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
byte[] t = new byte[size];
dataIn.readFully(t);
return new ByteSequence(t, 0, size);
@@ -616,10 +618,11 @@ protected void looseMarshalByteArray(OpenWireFormat wireFormat, byte[] data, Dat
}
}
- protected byte[] looseUnmarshalByteArray(DataInput dataIn) throws IOException {
+ protected byte[] looseUnmarshalByteArray(OpenWireFormat wireFormat, DataInput dataIn) throws IOException {
byte rc[] = null;
if (dataIn.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
rc = new byte[size];
dataIn.readFully(rc);
}
@@ -635,10 +638,11 @@ protected void looseMarshalByteSequence(OpenWireFormat wireFormat, ByteSequence
}
}
- protected ByteSequence looseUnmarshalByteSequence(DataInput dataIn) throws IOException {
+ protected ByteSequence looseUnmarshalByteSequence(OpenWireFormat wireFormat, DataInput dataIn) throws IOException {
ByteSequence rc = null;
if (dataIn.readBoolean()) {
int size = dataIn.readInt();
+ OpenWireUtil.validateBufferSize(wireFormat, size);
byte[] t = new byte[size];
dataIn.readFully(t);
rc = new ByteSequence(t, 0, size);
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v9/ConnectionControlMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v9/ConnectionControlMarshaller.java
index b28b1916056..5dca9f3085e 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v9/ConnectionControlMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v9/ConnectionControlMarshaller.java
@@ -74,7 +74,7 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setConnectedBrokers(tightUnmarshalString(dataIn, bs));
info.setReconnectTo(tightUnmarshalString(dataIn, bs));
info.setRebalanceConnection(bs.readBoolean());
- info.setToken(tightUnmarshalByteArray(dataIn, bs));
+ info.setToken(tightUnmarshalByteArray(wireFormat, dataIn, bs));
}
@@ -142,7 +142,7 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setConnectedBrokers(looseUnmarshalString(dataIn));
info.setReconnectTo(looseUnmarshalString(dataIn));
info.setRebalanceConnection(dataIn.readBoolean());
- info.setToken(looseUnmarshalByteArray(dataIn));
+ info.setToken(looseUnmarshalByteArray(wireFormat, dataIn));
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v9/MessageMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v9/MessageMarshaller.java
index b39ce065a0a..2c1db936160 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v9/MessageMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v9/MessageMarshaller.java
@@ -69,8 +69,8 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setReplyTo((org.apache.activemq.command.ActiveMQDestination) tightUnmarsalNestedObject(wireFormat, dataIn, bs));
info.setTimestamp(tightUnmarshalLong(wireFormat, dataIn, bs));
info.setType(tightUnmarshalString(dataIn, bs));
- info.setContent(tightUnmarshalByteSequence(dataIn, bs));
- info.setMarshalledProperties(tightUnmarshalByteSequence(dataIn, bs));
+ info.setContent(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
+ info.setMarshalledProperties(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
info.setDataStructure((org.apache.activemq.command.DataStructure) tightUnmarsalNestedObject(wireFormat, dataIn, bs));
info.setTargetConsumerId((org.apache.activemq.command.ConsumerId) tightUnmarsalCachedObject(wireFormat, dataIn, bs));
info.setCompressed(bs.readBoolean());
@@ -225,8 +225,8 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setReplyTo((org.apache.activemq.command.ActiveMQDestination) looseUnmarsalNestedObject(wireFormat, dataIn));
info.setTimestamp(looseUnmarshalLong(wireFormat, dataIn));
info.setType(looseUnmarshalString(dataIn));
- info.setContent(looseUnmarshalByteSequence(dataIn));
- info.setMarshalledProperties(looseUnmarshalByteSequence(dataIn));
+ info.setContent(looseUnmarshalByteSequence(wireFormat, dataIn));
+ info.setMarshalledProperties(looseUnmarshalByteSequence(wireFormat, dataIn));
info.setDataStructure((org.apache.activemq.command.DataStructure) looseUnmarsalNestedObject(wireFormat, dataIn));
info.setTargetConsumerId((org.apache.activemq.command.ConsumerId) looseUnmarsalCachedObject(wireFormat, dataIn));
info.setCompressed(dataIn.readBoolean());
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v9/PartialCommandMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v9/PartialCommandMarshaller.java
index d4445bdd4b8..9278ddc8ca6 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v9/PartialCommandMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v9/PartialCommandMarshaller.java
@@ -67,7 +67,7 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
PartialCommand info = (PartialCommand)o;
info.setCommandId(dataIn.readInt());
- info.setData(tightUnmarshalByteArray(dataIn, bs));
+ info.setData(tightUnmarshalByteArray(wireFormat, dataIn, bs));
}
@@ -113,7 +113,7 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
PartialCommand info = (PartialCommand)o;
info.setCommandId(dataIn.readInt());
- info.setData(looseUnmarshalByteArray(dataIn));
+ info.setData(looseUnmarshalByteArray(wireFormat, dataIn));
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v9/WireFormatInfoMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v9/WireFormatInfoMarshaller.java
index 005afb59f1b..190a3f55fc1 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v9/WireFormatInfoMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v9/WireFormatInfoMarshaller.java
@@ -71,7 +71,7 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setMagic(tightUnmarshalConstByteArray(dataIn, bs, 8));
info.setVersion(dataIn.readInt());
- info.setMarshalledProperties(tightUnmarshalByteSequence(dataIn, bs));
+ info.setMarshalledProperties(tightUnmarshalByteSequence(wireFormat, dataIn, bs));
info.afterUnmarshall(wireFormat);
@@ -129,7 +129,7 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
info.setMagic(looseUnmarshalConstByteArray(dataIn, 8));
info.setVersion(dataIn.readInt());
- info.setMarshalledProperties(looseUnmarshalByteSequence(dataIn));
+ info.setMarshalledProperties(looseUnmarshalByteSequence(wireFormat, dataIn));
info.afterUnmarshall(wireFormat);
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v9/XATransactionIdMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v9/XATransactionIdMarshaller.java
index 525fda5765f..231fdfa1fa9 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v9/XATransactionIdMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v9/XATransactionIdMarshaller.java
@@ -67,8 +67,8 @@ public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
XATransactionId info = (XATransactionId)o;
info.setFormatId(dataIn.readInt());
- info.setGlobalTransactionId(tightUnmarshalByteArray(dataIn, bs));
- info.setBranchQualifier(tightUnmarshalByteArray(dataIn, bs));
+ info.setGlobalTransactionId(tightUnmarshalByteArray(wireFormat, dataIn, bs));
+ info.setBranchQualifier(tightUnmarshalByteArray(wireFormat, dataIn, bs));
}
@@ -116,8 +116,8 @@ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn
XATransactionId info = (XATransactionId)o;
info.setFormatId(dataIn.readInt());
- info.setGlobalTransactionId(looseUnmarshalByteArray(dataIn));
- info.setBranchQualifier(looseUnmarshalByteArray(dataIn));
+ info.setGlobalTransactionId(looseUnmarshalByteArray(wireFormat, dataIn));
+ info.setBranchQualifier(looseUnmarshalByteArray(wireFormat, dataIn));
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/util/IOExceptionSupport.java b/activemq-client/src/main/java/org/apache/activemq/util/IOExceptionSupport.java
index 0db3ce4fc42..6941726d3b8 100644
--- a/activemq-client/src/main/java/org/apache/activemq/util/IOExceptionSupport.java
+++ b/activemq-client/src/main/java/org/apache/activemq/util/IOExceptionSupport.java
@@ -52,7 +52,13 @@ public static IOException create(Exception cause) {
public static IOException createFrameSizeException(int size, long maxSize) {
return new MaxFrameSizeExceededException("Frame size of " + toHumanReadableSizeString(size) +
- " larger than max allowed " + toHumanReadableSizeString(maxSize));
+ " is larger than max allowed " + toHumanReadableSizeString(maxSize));
+ }
+
+ public static IOException createFrameSizeBufferException(int bufferSize, long frameSize) {
+ return new IOException("Estimated allocated buffer size of "
+ + toHumanReadableSizeString(bufferSize) + " is larger than frame size of "
+ + toHumanReadableSizeString(frameSize));
}
private static String toHumanReadableSizeString(final int size) {
diff --git a/activemq-client/src/test/java/org/apache/activemq/openwire/OpenWireUtilTest.java b/activemq-client/src/test/java/org/apache/activemq/openwire/OpenWireUtilTest.java
new file mode 100644
index 00000000000..5cf77ea87df
--- /dev/null
+++ b/activemq-client/src/test/java/org/apache/activemq/openwire/OpenWireUtilTest.java
@@ -0,0 +1,103 @@
+package org.apache.activemq.openwire;
+
+
+import jakarta.jms.InvalidClientIDException;
+import jakarta.jms.JMSException;
+import org.apache.activemq.ActiveMQConnection;
+import org.apache.activemq.MaxFrameSizeExceededException;
+import org.apache.activemq.command.WireFormatInfo;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class OpenWireUtilTest {
+
+ @Test
+ public void testValidateIsThrowable() {
+ OpenWireUtil.validateIsThrowable(Exception.class);
+ OpenWireUtil.validateIsThrowable(Throwable.class);
+ OpenWireUtil.validateIsThrowable(JMSException.class);
+ OpenWireUtil.validateIsThrowable(InvalidClientIDException.class);
+
+ try {
+ OpenWireUtil.validateIsThrowable(String.class);
+ fail("Not a valid Throwable");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ OpenWireUtil.validateIsThrowable(ActiveMQConnection.class);
+ fail("Not a valid Throwable");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testConvertJmsPackage() {
+ // should not change
+ assertEquals(InvalidClientIDException.class.getName(),
+ OpenWireUtil.convertJmsPackage(InvalidClientIDException.class.getName()));
+
+ // should convert to correct exception type
+ assertEquals(InvalidClientIDException.class.getName(),
+ OpenWireUtil.convertJmsPackage(OpenWireUtil.jmsPackageToReplace + ".InvalidClientIDException"));
+ }
+
+ @Test
+ public void testValidateBufferSize() throws IOException {
+ OpenWireFormatFactory factory = new OpenWireFormatFactory();
+
+ var wireFormat = (OpenWireFormat) factory.createWireFormat();
+
+ // Nothing set, no validation
+ OpenWireUtil.validateBufferSize(wireFormat, 2048);
+
+ // verify max frame check works
+ try {
+ wireFormat.setMaxFrameSize(1024);
+ OpenWireUtil.validateBufferSize(wireFormat, 2048);
+ fail("should have failed");
+ } catch (MaxFrameSizeExceededException e) {
+ // expected
+ }
+
+ // rest max frame size back so we can test validating current size
+ // is less than expected buffer size
+ wireFormat.setMaxFrameSize(OpenWireFormat.DEFAULT_MAX_FRAME_SIZE);
+ WireFormatInfo wfi = new WireFormatInfo();
+ wfi.setProperty("test", "test");
+
+ // should be no error for the first 2 calls, last call should
+ // go over frame size and error
+ initContext(wireFormat, 2048);
+ OpenWireUtil.validateBufferSize(wireFormat, 1024);
+ OpenWireUtil.validateBufferSize(wireFormat, 1024);
+ try {
+ OpenWireUtil.validateBufferSize(wireFormat, 1);
+ fail("should have failed");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void initContext(OpenWireFormat format, int frameSize) throws IOException {
+ try {
+ Field mcThreadLocalField = OpenWireFormat.class.getDeclaredField("marshallingContext");
+ mcThreadLocalField.setAccessible(true);
+ var mcThreadLocal = (ThreadLocal) mcThreadLocalField.get(format);
+ var context = new OpenWireFormat.MarshallingContext();
+ context.setFrameSize(frameSize);
+ mcThreadLocal.set(context);
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
diff --git a/activemq-client/src/test/java/org/apache/activemq/openwire/OpenWireValidationTest.java b/activemq-client/src/test/java/org/apache/activemq/openwire/OpenWireValidationTest.java
index e5c7687ee91..bbf99fc29a9 100644
--- a/activemq-client/src/test/java/org/apache/activemq/openwire/OpenWireValidationTest.java
+++ b/activemq-client/src/test/java/org/apache/activemq/openwire/OpenWireValidationTest.java
@@ -16,19 +16,24 @@
*/
package org.apache.activemq.openwire;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
+import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.activemq.command.CommandTypes;
-import org.apache.activemq.command.ExceptionResponse;
+
+import javassist.util.proxy.MethodHandler;
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.ProxyObject;
+import org.apache.activemq.command.*;
+import org.apache.activemq.openwire.v1.BaseDataStreamMarshaller;
+import org.apache.activemq.transport.nio.NIOInputStream;
import org.apache.activemq.util.ByteSequence;
import org.junit.Before;
import org.junit.Test;
@@ -36,9 +41,10 @@
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
+import static org.junit.Assert.*;
+
/**
- * Test that Openwire marshalling will validate Throwable types during
- * unmarshalling commands that contain a Throwable
+ * Test that Openwire marshalling will validate commands correctly
*/
@RunWith(Parameterized.class)
public class OpenWireValidationTest {
@@ -63,7 +69,7 @@ public static Collection