Repository: cassandra Updated Branches: refs/heads/trunk b440de5fe -> f6924a1de
Remove unnecessary check in Frame patch by Benjamin Lerer; reviewed by Sylvain Lebresne for CASSANDRA-10146 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/7d8663da Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/7d8663da Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/7d8663da Branch: refs/heads/trunk Commit: 7d8663da7702cb009e44594b2b040cff81f15dea Parents: 9dd8471 Author: blerer <[email protected]> Authored: Thu Sep 10 21:46:41 2015 +0200 Committer: blerer <[email protected]> Committed: Thu Sep 10 21:46:41 2015 +0200 ---------------------------------------------------------------------- .../org/apache/cassandra/transport/Frame.java | 6 --- .../cassandra/transport/ProtocolErrorTest.java | 39 ++++++-------------- 2 files changed, 11 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/7d8663da/src/java/org/apache/cassandra/transport/Frame.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/transport/Frame.java b/src/java/org/apache/cassandra/transport/Frame.java index f5c3834..021143e 100644 --- a/src/java/org/apache/cassandra/transport/Frame.java +++ b/src/java/org/apache/cassandra/transport/Frame.java @@ -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) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/7d8663da/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java b/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java index 9910167..80d2b17 100644 --- a/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java +++ b/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java @@ -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")); } } }
