Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 42BF318EBF for ; Thu, 10 Sep 2015 20:09:57 +0000 (UTC) Received: (qmail 70911 invoked by uid 500); 10 Sep 2015 20:09:52 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 70870 invoked by uid 500); 10 Sep 2015 20:09:52 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 70829 invoked by uid 99); 10 Sep 2015 20:09:51 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Sep 2015 20:09:51 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D08A4E0FB7; Thu, 10 Sep 2015 20:09:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: blerer@apache.org To: commits@cassandra.apache.org Date: Thu, 10 Sep 2015 20:09:51 -0000 Message-Id: <76e17453549540a795557c4d5d0a42b1@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/7] cassandra git commit: Remove unnecessary check in Frame 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 Authored: Thu Sep 10 21:46:41 2015 +0200 Committer: blerer 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 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 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 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")); } } }