mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-498 - check max frame size before umarshalling commands
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1133956 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e5e99d72f3
commit
8a82119dd5
|
@ -269,7 +269,10 @@ public final class OpenWireFormat implements WireFormat {
|
||||||
public Object unmarshal(DataInput dis) throws IOException {
|
public Object unmarshal(DataInput dis) throws IOException {
|
||||||
DataInput dataIn = dis;
|
DataInput dataIn = dis;
|
||||||
if (!sizePrefixDisabled) {
|
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();
|
// int size = dis.readInt();
|
||||||
// byte[] data = new byte[size];
|
// byte[] data = new byte[size];
|
||||||
// dis.readFully(data);
|
// dis.readFully(data);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
import org.apache.activemq.command.ActiveMQTextMessage;
|
||||||
import org.apache.activemq.command.SessionId;
|
import org.apache.activemq.command.SessionId;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -92,6 +93,32 @@ public class NumberRangesWhileMarshallingTest extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
openWireformat = createOpenWireFormat();
|
openWireformat = createOpenWireFormat();
|
||||||
|
|
Loading…
Reference in New Issue