Remove unnecessary check in Frame

patch by Benjamin Lerer; reviewed by Sylvain Lebresne for CASSANDRA-10146
This commit is contained in:
blerer 2015-09-10 21:46:41 +02:00
parent 9dd847135f
commit 7d8663da77
2 changed files with 11 additions and 34 deletions

View File

@ -219,12 +219,6 @@ public class Frame
long bodyLength = buffer.getUnsignedInt(idx);
idx += Header.BODY_LENGTH_SIZE;
if (bodyLength < 0)
{
buffer.skipBytes(headerLength);
throw ErrorMessage.wrap(new ProtocolException("Invalid frame body length: " + bodyLength), streamId);
}
long frameLength = bodyLength + headerLength;
if (frameLength > MAX_FRAME_LENGTH)
{

View File

@ -26,6 +26,8 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.apache.cassandra.transport.Message.Direction.*;
public class ProtocolErrorTest {
@Test
@ -36,7 +38,7 @@ public class ProtocolErrorTest {
List<Object> results = new ArrayList<>();
// should generate a protocol exception for using a protocol version higher than the current version
byte[] frame = new byte[] {
(byte) ((Server.CURRENT_VERSION + 1) & Frame.PROTOCOL_VERSION_MASK), // direction & version
(byte) RESPONSE.addToVersion(Server.CURRENT_VERSION + 1), // direction & version
0x00, // flags
0x01, // stream ID
0x09, // opcode
@ -52,6 +54,7 @@ public class ProtocolErrorTest {
dec.decode(null, buf, results);
Assert.fail("Expected protocol error");
} catch (ProtocolException e) {
Assert.assertTrue(e.getMessage().contains("Invalid or unsupported protocol version"));
}
}
@ -64,7 +67,7 @@ public class ProtocolErrorTest {
// should generate a protocol exception for using a response frame with
// a prepare op, ensure that it comes back with stream ID 1
byte[] frame = new byte[] {
(byte) 0x82, // direction & version
(byte) RESPONSE.addToVersion(2), // direction & version
0x00, // flags
0x01, // stream ID
0x09, // opcode
@ -82,29 +85,7 @@ public class ProtocolErrorTest {
} catch (ErrorMessage.WrappedException e) {
// make sure the exception has the correct stream ID
Assert.assertEquals(1, e.getStreamId());
}
}
@Test
public void testNegativeBodyLength() throws Exception
{
Frame.Decoder dec = new Frame.Decoder(null);
List<Object> results = new ArrayList<>();
byte[] frame = new byte[] {
(byte) 0x82, // direction & version
0x00, // flags
0x01, // stream ID
0x09, // opcode
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, // body length (-1)
};
ByteBuf buf = Unpooled.wrappedBuffer(frame);
try {
dec.decode(null, buf, results);
Assert.fail("Expected protocol error");
} catch (ErrorMessage.WrappedException e) {
// make sure the exception has the correct stream ID
Assert.assertEquals(1, e.getStreamId());
Assert.assertTrue(e.getMessage().contains("Wrong protocol direction"));
}
}
@ -115,19 +96,21 @@ public class ProtocolErrorTest {
List<Object> results = new ArrayList<>();
byte[] frame = new byte[] {
(byte) 0x82, // direction & version
(byte) (byte) REQUEST.addToVersion(2), // direction & version
0x00, // flags
0x01, // stream ID
0x09, // opcode
0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff, // body length
0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00, // body length
};
ByteBuf buf = Unpooled.wrappedBuffer(frame);
byte[] body = new byte[0x10000000];
ByteBuf buf = Unpooled.wrappedBuffer(frame, body);
try {
dec.decode(null, buf, results);
Assert.fail("Expected protocol error");
} catch (ErrorMessage.WrappedException e) {
// make sure the exception has the correct stream ID
Assert.assertEquals(1, e.getStreamId());
Assert.assertTrue(e.getMessage().contains("Request is too big"));
}
}
}