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 data() { // This will make sure that we don't forget to update this test to include // any future versions that are generated assertTrue("List of Openwire versions does not include latest version", - versions.contains((int)CommandTypes.PROTOCOL_VERSION)); + versions.contains((int) CommandTypes.PROTOCOL_VERSION)); return versionObjs; } @@ -72,21 +78,98 @@ public OpenWireValidationTest(int version) { this.version = version; } + @Test + public void testLooseUnmarshalByteSequenceValidation() throws Exception { + testUnmarshalByteSequenceValidation(false); + } + + @Test + public void testTightUnmarshalByteSequenceValidation() throws Exception { + testUnmarshalByteSequenceValidation(true); + } + + @Test + public void testLooseUnmarshalByteArray() throws Exception { + testUnmarshalByteArray(false); + } + + @Test + public void testTightUnmarshalByteArray() throws Exception { + testUnmarshalByteArray(true); + } + + // WireFormatInfo eventually delegates to BaseDataStreamMarshaller#tightUnmarshalByteSequence() and + // BaseDataStreamMarshaller#looseUnmarshalByteSequence() + private void testUnmarshalByteSequenceValidation(boolean tightEncoding) throws Exception { + WireFormatInfo wfi = new WireFormatInfo(); + wfi.setProperty("prop1", "val1"); + testUnmarshal(wfi, tightEncoding); + } + + // PartialCommand eventually delegates to BaseDataStreamMarshaller#tightUnmarshalByteArray() + // and BaseDataStreamMarshaller#looseUnmarshalByteArray() + private void testUnmarshalByteArray(boolean tightEncoding) throws Exception { + PartialCommand pc = new PartialCommand(); + pc.setData("bytes".getBytes(StandardCharsets.UTF_8)); + testUnmarshal(pc, tightEncoding); + } + + private void testUnmarshal(Command command, boolean tightEncoding) throws Exception { + var format = setupWireFormat(tightEncoding); + ByteSequence bss = format.marshal(command); + try { + // We should get an exception from an invalid size value that is too large + // Test OpenWireFormat#unmarshal(ByteSequence) method + format.unmarshal(bss); + fail("Should have received an IOException"); + } catch (IOException io) { + assertTrue(io.getMessage().contains("Estimated allocated buffer size")); + assertTrue(io.getMessage().contains("is larger than frame size")); + } + // Verify thread local is cleared even after exception + assertNull(format.getMarshallingContext()); + + try { + // We should get an exception from an invalid size value that is too large + // Test OpenWireFormat#unmarshal(DataInput) method + format.unmarshal(new DataInputStream(new NIOInputStream( + ByteBuffer.wrap(bss.toArray())))); + fail("Should have received an IOException"); + } catch (IOException io) { + assertTrue(io.getMessage().contains("Estimated allocated buffer size")); + assertTrue(io.getMessage().contains("is larger than frame size")); + } + // Verify thread local is cleared even after exception + assertNull(format.getMarshallingContext()); + } + + // Verify MarshallingContext thread local is cleared where there is + // successful unmarshalling and no error. The other tests that check + // validation works if invalid size will validate the context is cleared + // when there is an error + @Test + public void testUnmarshalNoErrorClearContext() throws Exception { + var format = new OpenWireFormat(); + ByteSequence bss = format.marshal(new ConnectionInfo()); + + // make sure context cleared after calling + // OpenWireFormat#unmarshal(ByteSequence) method + format.unmarshal(bss); + assertNull(format.getMarshallingContext()); + + // Make sure context cleared after calling + // OpenWireFormat#unmarshal(DataInput) method + format.unmarshal(new DataInputStream(new NIOInputStream( + ByteBuffer.wrap(bss.toArray())))); + assertNull(format.getMarshallingContext()); + } + @Test public void testOpenwireThrowableValidation() throws Exception { // Create a format which will use loose encoding by default // The code for handling exception creation is shared between both // tight/loose encoding so only need to test 1 - OpenWireFormat format = new OpenWireFormat(); - - // Override the marshaller map with a custom impl to purposely marshal a class type that is - // not a Throwable for testing the unmarshaller - Class marshallerFactory = getMarshallerFactory(); - Method createMarshallerMap = marshallerFactory.getMethod("createMarshallerMap", OpenWireFormat.class); - DataStreamMarshaller[] map = (DataStreamMarshaller[]) createMarshallerMap.invoke(marshallerFactory, format); - map[ExceptionResponse.DATA_STRUCTURE_TYPE] = getExceptionMarshaller(); - // This will trigger updating the marshaller from the marshaller map with the right version - format.setVersion(version); + var format = setupWireFormat(false); // Build the response and try to unmarshal which should give an IllegalArgumentExeption on unmarshall // as the test marshaller should have encoded a class type that is not a Throwable @@ -102,6 +185,23 @@ public void testOpenwireThrowableValidation() throws Exception { assertFalse(initialized.get()); } + private OpenWireFormat setupWireFormat(boolean tightEncoding) throws Exception { + // Create a format + OpenWireFormat format = new OpenWireFormat(); + format.setTightEncodingEnabled(tightEncoding); + + // Override the marshaller map with a custom impl to purposely marshal a bad size value + Class marshallerFactory = getMarshallerFactory(); + Method createMarshallerMap = marshallerFactory.getMethod("createMarshallerMap", OpenWireFormat.class); + DataStreamMarshaller[] map = (DataStreamMarshaller[]) createMarshallerMap.invoke(marshallerFactory, format); + map[ExceptionResponse.DATA_STRUCTURE_TYPE] = getExceptionMarshaller(); + map[WireFormatInfo.DATA_STRUCTURE_TYPE] = getWireFormatInfoMarshaller(); + map[PartialCommand.DATA_STRUCTURE_TYPE] = getPartialCommandMarshaller(); + // This will trigger updating the marshaller from the marshaller map with the right version + format.setVersion(version); + return format; + } + static class NotAThrowable { private String message; @@ -181,4 +281,127 @@ protected void looseMarshalThrowable(OpenWireFormat wireFormat, Throwable o, } } + // Create test marshallers for all non-legacy versions + // WireFormatInfo will test the bytesequence marshallers + protected DataStreamMarshaller getWireFormatInfoMarshaller() { + switch (version) { + case 12: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v12.WireFormatInfoMarshaller()); + case 11: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v11.WireFormatInfoMarshaller()); + case 10: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v10.WireFormatInfoMarshaller()); + case 9: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v9.WireFormatInfoMarshaller()); + case 1: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v1.WireFormatInfoMarshaller()); + default: + throw new IllegalArgumentException("Unknown OpenWire version of " + version); + } + } + + // PartialCommand will test the byte array marshallers + protected DataStreamMarshaller getPartialCommandMarshaller() { + switch (version) { + case 12: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v12.PartialCommandMarshaller()); + case 11: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v11.PartialCommandMarshaller()); + case 10: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v10.PartialCommandMarshaller()); + case 9: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v9.PartialCommandMarshaller()); + case 1: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v1.PartialCommandMarshaller()); + default: + throw new IllegalArgumentException("Unknown OpenWire version of " + version); + } + } + + protected static void badTightMarshalByteSequence(ByteSequence data, DataOutput dataOut, + BooleanStream bs) throws IOException { + if (bs.readBoolean()) { + // Write an invalid length that is much larger than it should be + dataOut.writeInt(data.getLength() * 10); + dataOut.write(data.getData(), data.getOffset(), data.getLength()); + } + } + + protected static void badLooseMarshalByteSequence(ByteSequence data, DataOutput dataOut) + throws IOException { + dataOut.writeBoolean(data != null); + if (data != null) { + // Write an invalid length that is much larger than it should be + dataOut.writeInt(data.getLength() * 10); + dataOut.write(data.getData(), data.getOffset(), data.getLength()); + } + } + + protected static void badLooseMarshalByteArray(byte[] data, + DataOutput dataOut) throws IOException { + dataOut.writeBoolean(data != null); + if (data != null) { + // Write an invalid length that is much larger than it should be + dataOut.writeInt(data.length * 10); + dataOut.write(data); + } + } + + protected static void badTightMarshalByteArray(byte[] data, DataOutput dataOut, + BooleanStream bs) throws IOException { + if (bs.readBoolean()) { + // Write an invalid length that is much larger than it should be + dataOut.writeInt(data.length * 10); + dataOut.write(data); + } + } + + // This will create a proxy object to wrap the marhallers so that we can intercept + // both the byte and bytesequence methods to write bad sizes for testing + protected DataStreamMarshaller proxyBadBufferCommand(DataStreamMarshaller marshaller) { + ProxyFactory factory = new ProxyFactory(); + factory.setSuperclass(marshaller.getClass()); + Class clazz = factory.createClass(); + + try { + DataStreamMarshaller instance = (DataStreamMarshaller) clazz.getConstructor().newInstance(); + ((ProxyObject) instance).setHandler(new BadBufferProxy()); + return instance; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected static class BadBufferProxy implements MethodHandler { + + @Override + public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable { + Object result = null; + + try { + // This handles writing a bad size for all 4 types of methods that should validate + switch (thisMethod.getName()) { + case "looseMarshalByteArray": + badLooseMarshalByteArray((byte[]) args[1], (DataOutput) args[2]); + break; + case "tightMarshalByteArray2": + badTightMarshalByteArray((byte[]) args[0], (DataOutput) args[1], (BooleanStream) args[2]); + break; + case "looseMarshalByteSequence": + badLooseMarshalByteSequence((ByteSequence) args[1], (DataOutput) args[2]); + break; + case "tightMarshalByteSequence2": + badTightMarshalByteSequence((ByteSequence) args[0], (DataOutput) args[1], (BooleanStream) args[2]); + break; + default: + result = proceed.invoke(self, args); + break; + } + } catch (InvocationTargetException e) { + throw e.getCause(); + } + + return result; + } + } } diff --git a/activemq-openwire-legacy/pom.xml b/activemq-openwire-legacy/pom.xml index 93d51ff80eb..6feea425197 100644 --- a/activemq-openwire-legacy/pom.xml +++ b/activemq-openwire-legacy/pom.xml @@ -47,6 +47,11 @@ junit test + + org.javassist + javassist + test + diff --git a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/BaseDataStreamMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/BaseDataStreamMarshaller.java index ed8c9044577..548cffc0a62 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/BaseDataStreamMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/MessageMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/MessageMarshaller.java index 7ef69bfeb08..cf4809fbe41 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/MessageMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/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()); @@ -199,8 +199,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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/PartialCommandMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/PartialCommandMarshaller.java index caf762aa7e6..667b17246c7 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/PartialCommandMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/WireFormatInfoMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/WireFormatInfoMarshaller.java index 4bde98948f9..334bde464cd 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/WireFormatInfoMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/XATransactionIdMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/XATransactionIdMarshaller.java index 0cbb3d66066..4114852e44b 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/XATransactionIdMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v2/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/BaseDataStreamMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/BaseDataStreamMarshaller.java index 4199157a115..3487cd2643e 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/BaseDataStreamMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/MessageMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/MessageMarshaller.java index a8bc1670ecd..f83e4be31d6 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/MessageMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/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()); @@ -218,8 +218,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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/PartialCommandMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/PartialCommandMarshaller.java index dbe353df45e..444f4b0d66c 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/PartialCommandMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/WireFormatInfoMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/WireFormatInfoMarshaller.java index 88f01343b0e..1dda23a5b0c 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/WireFormatInfoMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/XATransactionIdMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/XATransactionIdMarshaller.java index 70ffde520c5..c771239a86a 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/XATransactionIdMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v3/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/BaseDataStreamMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/BaseDataStreamMarshaller.java index 2c9720512c1..9127fa73d96 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/BaseDataStreamMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/MessageMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/MessageMarshaller.java index 8c844da475d..fcd919c9e0b 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/MessageMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/PartialCommandMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/PartialCommandMarshaller.java index 3f539c0a09b..2709e4d262e 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/PartialCommandMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/WireFormatInfoMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/WireFormatInfoMarshaller.java index ec65a8c6a29..cb84511146d 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/WireFormatInfoMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/XATransactionIdMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/XATransactionIdMarshaller.java index 49073d29951..7ef00d27937 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/XATransactionIdMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v4/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/BaseDataStreamMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/BaseDataStreamMarshaller.java index 264f260a7d5..114f9390acc 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/BaseDataStreamMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/MessageMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/MessageMarshaller.java index 8314455ea6c..8671cb92252 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/MessageMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/PartialCommandMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/PartialCommandMarshaller.java index 8537d480ab7..450469abea5 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/PartialCommandMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/WireFormatInfoMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/WireFormatInfoMarshaller.java index b6e822265c4..e3d473c2515 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/WireFormatInfoMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/XATransactionIdMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/XATransactionIdMarshaller.java index 40d5d57f662..c950dcdfc7a 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/XATransactionIdMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v5/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/BaseDataStreamMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/BaseDataStreamMarshaller.java index fee3c0e4b53..544abed173c 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/BaseDataStreamMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/MessageMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/MessageMarshaller.java index a2c7ad53396..c511b689787 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/MessageMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/PartialCommandMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/PartialCommandMarshaller.java index 705169c7ff4..46430cfb56b 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/PartialCommandMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/WireFormatInfoMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/WireFormatInfoMarshaller.java index d4bcecc2a90..51a1dc5b9f2 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/WireFormatInfoMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/XATransactionIdMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/XATransactionIdMarshaller.java index fc968e379c1..c87251cab02 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/XATransactionIdMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v6/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/BaseDataStreamMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/BaseDataStreamMarshaller.java index db8aeb73cc2..88afd740b87 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/BaseDataStreamMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/MessageMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/MessageMarshaller.java index 2e05c4c684b..f0a94c9e54b 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/MessageMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/PartialCommandMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/PartialCommandMarshaller.java index 8a4c8fac019..0bcfa5df3f4 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/PartialCommandMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/WireFormatInfoMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/WireFormatInfoMarshaller.java index 9e4c12c470d..1ebd9225a66 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/WireFormatInfoMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/XATransactionIdMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/XATransactionIdMarshaller.java index 3a02551a4c4..b93db8439b6 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/XATransactionIdMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v7/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/BaseDataStreamMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/BaseDataStreamMarshaller.java index 47a0165ae52..4cc312309da 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/BaseDataStreamMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/ConnectionControlMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/ConnectionControlMarshaller.java index 32c5dd5b7eb..8267934dfbe 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/ConnectionControlMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/MessageMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/MessageMarshaller.java index f6e5f3d5fad..7ac54ca30bd 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/MessageMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/PartialCommandMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/PartialCommandMarshaller.java index 67c4b25b311..4f294639b5b 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/PartialCommandMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/WireFormatInfoMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/WireFormatInfoMarshaller.java index c7ea8be853f..4660e6344ef 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/WireFormatInfoMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/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-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/XATransactionIdMarshaller.java b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/XATransactionIdMarshaller.java index 002945e991b..8f504012038 100644 --- a/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/XATransactionIdMarshaller.java +++ b/activemq-openwire-legacy/src/main/java/org/apache/activemq/openwire/v8/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-openwire-legacy/src/test/java/org/apache/activemq/openwire/OpenWireLegacyValidationTest.java b/activemq-openwire-legacy/src/test/java/org/apache/activemq/openwire/OpenWireLegacyValidationTest.java index daee1344b31..0c051ffe2b8 100644 --- a/activemq-openwire-legacy/src/test/java/org/apache/activemq/openwire/OpenWireLegacyValidationTest.java +++ b/activemq-openwire-legacy/src/test/java/org/apache/activemq/openwire/OpenWireLegacyValidationTest.java @@ -21,13 +21,13 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.apache.activemq.util.ByteSequence; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; /** - * Test that Openwire marshalling for legacy versions will validate Throwable types during - * unmarshalling commands that contain a Throwable + * Test that Openwire marshalling for legacy versions will validate certain commands correctly */ @RunWith(Parameterized.class) public class OpenWireLegacyValidationTest extends OpenWireValidationTest { @@ -126,4 +126,46 @@ protected void looseMarshalThrowable(OpenWireFormat wireFormat, Throwable o, } } + protected DataStreamMarshaller getWireFormatInfoMarshaller() { + switch (version) { + case 2: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v2.WireFormatInfoMarshaller()); + case 3: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v3.WireFormatInfoMarshaller()); + case 4: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v4.WireFormatInfoMarshaller()); + case 5: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v5.WireFormatInfoMarshaller()); + case 6: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v6.WireFormatInfoMarshaller()); + case 7: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v7.WireFormatInfoMarshaller()); + case 8: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v8.WireFormatInfoMarshaller()); + default: + throw new IllegalArgumentException("Unknown OpenWire version of " + version); + } + } + + protected DataStreamMarshaller getPartialCommandMarshaller() { + switch (version) { + case 2: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v2.PartialCommandMarshaller()); + case 3: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v3.PartialCommandMarshaller()); + case 4: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v4.PartialCommandMarshaller()); + case 5: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v5.PartialCommandMarshaller()); + case 6: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v6.PartialCommandMarshaller()); + case 7: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v7.PartialCommandMarshaller()); + case 8: + return proxyBadBufferCommand(new org.apache.activemq.openwire.v8.PartialCommandMarshaller()); + default: + throw new IllegalArgumentException("Unknown OpenWire version of " + version); + } + } + } diff --git a/pom.xml b/pom.xml index a41d065d5ef..f89fe45c3b4 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,7 @@ [11,13) 3.6.0 9.0.65 + 3.30.2-GA 1.5.4 2.13.1 2.1.2 @@ -924,6 +925,11 @@ jettison ${jettison-version} + + org.javassist + javassist + ${javassist-version} + annogen