You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by de...@apache.org on 2011/06/09 18:01:16 UTC
svn commit: r1133956 - in /activemq/trunk/activemq-core/src:
main/java/org/apache/activemq/openwire/OpenWireFormat.java
test/java/org/apache/activemq/openwire/NumberRangesWhileMarshallingTest.java
Author: dejanb
Date: Thu Jun 9 16:01:16 2011
New Revision: 1133956
URL: http://svn.apache.org/viewvc?rev=1133956&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-498 - check max frame size before umarshalling commands
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/openwire/NumberRangesWhileMarshallingTest.java
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java?rev=1133956&r1=1133955&r2=1133956&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java Thu Jun 9 16:01:16 2011
@@ -269,7 +269,10 @@ public final class OpenWireFormat implem
public Object unmarshal(DataInput dis) throws IOException {
DataInput dataIn = dis;
if (!sizePrefixDisabled) {
- dis.readInt();
+ int size = dis.readInt();
+ if (size > maxFrameSize) {
+ throw new IOException("Frame size of " + (size / (1024 * 1024)) + " MB larger than max allowed " + (maxFrameSize / (1024 * 1024)) + " MB");
+ }
// int size = dis.readInt();
// byte[] data = new byte[size];
// dis.readFully(data);
Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/openwire/NumberRangesWhileMarshallingTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/openwire/NumberRangesWhileMarshallingTest.java?rev=1133956&r1=1133955&r2=1133956&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/openwire/NumberRangesWhileMarshallingTest.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/openwire/NumberRangesWhileMarshallingTest.java Thu Jun 9 16:01:16 2011
@@ -23,6 +23,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import junit.framework.TestCase;
+import org.apache.activemq.command.ActiveMQTextMessage;
import org.apache.activemq.command.SessionId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -92,6 +93,32 @@ public class NumberRangesWhileMarshallin
}
}
+ public void testMaxFrameSize() throws Exception {
+ OpenWireFormat wf = new OpenWireFormat();
+ wf.setMaxFrameSize(10);
+ ActiveMQTextMessage msg = new ActiveMQTextMessage();
+ msg.setText("This is a test");
+
+ writeObject(msg);
+ ds.writeInt(endOfStreamMarker);
+
+ // now lets read from the stream
+ ds.close();
+
+ ByteArrayInputStream in = new ByteArrayInputStream(buffer.toByteArray());
+ DataInputStream dis = new DataInputStream(in);
+
+ try {
+ wf.unmarshal(dis);
+ } catch (IOException ioe) {
+ return;
+ }
+
+ fail("Should fail because of the large frame size");
+
+
+ }
+
protected void setUp() throws Exception {
super.setUp();
openWireformat = createOpenWireFormat();