Repository: qpid-broker-j Updated Branches: refs/heads/master d4d408f27 -> 2402b6379
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/2402b637/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DataSectionConstructor.java ---------------------------------------------------------------------- diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DataSectionConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DataSectionConstructor.java index d9b331a..e27c878 100644 --- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DataSectionConstructor.java +++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DataSectionConstructor.java @@ -64,6 +64,10 @@ public class DataSectionConstructor implements DescribedTypeConstructor<DataSect final ValueHandler valueHandler) throws AmqpErrorException { + if (!QpidByteBufferUtils.hasRemaining(in)) + { + throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Insufficient data to decode data section."); + } int constructorByte = QpidByteBufferUtils.get(in) & 0xff; int sizeBytes; switch(constructorByte) @@ -102,6 +106,10 @@ public class DataSectionConstructor implements DescribedTypeConstructor<DataSect @Override protected void skipValue(final List<QpidByteBuffer> in) throws AmqpErrorException { + if (!QpidByteBufferUtils.hasRemaining(in, _sizeBytes)) + { + throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Insufficient data to decode data section."); + } int size; switch(_sizeBytes) { @@ -112,7 +120,11 @@ public class DataSectionConstructor implements DescribedTypeConstructor<DataSect size = QpidByteBufferUtils.getInt(in); break; default: - throw new AmqpErrorException(AmqpError.INVALID_FIELD, "Unexpected constructor type, can only be 1 or 4"); + throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Unexpected constructor type, can only be 1 or 4"); + } + if (!QpidByteBufferUtils.hasRemaining(in, size)) + { + throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Insufficient data to decode data section."); } QpidByteBufferUtils.skip(in, size); } http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/2402b637/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DescribedListSectionConstructor.java ---------------------------------------------------------------------- diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DescribedListSectionConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DescribedListSectionConstructor.java index d038f33..1a60c01 100644 --- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DescribedListSectionConstructor.java +++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DescribedListSectionConstructor.java @@ -45,6 +45,10 @@ public abstract class DescribedListSectionConstructor<S extends AbstractSection> final ValueHandler valueHandler) throws AmqpErrorException { + if (!QpidByteBufferUtils.hasRemaining(in)) + { + throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Insufficient data to decode section."); + } int constructorByte = QpidByteBufferUtils.get(in) & 0xff; int sizeBytes; switch(constructorByte) @@ -59,7 +63,7 @@ public abstract class DescribedListSectionConstructor<S extends AbstractSection> sizeBytes = 4; break; default: - throw new AmqpErrorException(ConnectionError.FRAMING_ERROR, + throw new AmqpErrorException(AmqpError.DECODE_ERROR, "The described section must always be a list"); } @@ -86,6 +90,10 @@ public abstract class DescribedListSectionConstructor<S extends AbstractSection> @Override protected void skipValue(final List<QpidByteBuffer> in) throws AmqpErrorException { + if (!QpidByteBufferUtils.hasRemaining(in, _sizeBytes)) + { + throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Insufficient data to decode section."); + } int size; switch(_sizeBytes) { @@ -99,7 +107,11 @@ public abstract class DescribedListSectionConstructor<S extends AbstractSection> size = QpidByteBufferUtils.getInt(in); break; default: - throw new AmqpErrorException(AmqpError.INVALID_FIELD, "Unexpected constructor type, can only be 0,1 or 4"); + throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Unexpected constructor type, can only be 0,1 or 4"); + } + if (!QpidByteBufferUtils.hasRemaining(in, size)) + { + throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Insufficient data to decode section."); } QpidByteBufferUtils.skip(in, size); } http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/2402b637/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DescribedMapSectionConstructor.java ---------------------------------------------------------------------- diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DescribedMapSectionConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DescribedMapSectionConstructor.java index 9c58321..c7793b5 100644 --- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DescribedMapSectionConstructor.java +++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/DescribedMapSectionConstructor.java @@ -47,6 +47,10 @@ public abstract class DescribedMapSectionConstructor<S extends AbstractSection> final ValueHandler valueHandler) throws AmqpErrorException { + if (!QpidByteBufferUtils.hasRemaining(in)) + { + throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Insufficient data to decode section."); + } int constructorByte = QpidByteBufferUtils.get(in) & 0xff; int sizeBytes; switch(constructorByte) @@ -86,6 +90,10 @@ public abstract class DescribedMapSectionConstructor<S extends AbstractSection> @Override protected void skipValue(final List<QpidByteBuffer> in) throws AmqpErrorException { + if (!QpidByteBufferUtils.hasRemaining(in, _sizeBytes)) + { + throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Insufficient data to decode section."); + } int size; switch(_sizeBytes) { @@ -96,7 +104,11 @@ public abstract class DescribedMapSectionConstructor<S extends AbstractSection> size = QpidByteBufferUtils.getInt(in); break; default: - throw new AmqpErrorException(AmqpError.INVALID_FIELD, "Unexpected constructor type, can only be 1 or 4"); + throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Unexpected constructor type, can only be 1 or 4"); + } + if (!QpidByteBufferUtils.hasRemaining(in, size)) + { + throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Insufficient data to decode section."); } QpidByteBufferUtils.skip(in, size); } http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/2402b637/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/ValueHandlerTest.java ---------------------------------------------------------------------- diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/ValueHandlerTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/ValueHandlerTest.java new file mode 100644 index 0000000..d142b15 --- /dev/null +++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/ValueHandlerTest.java @@ -0,0 +1,196 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.qpid.server.protocol.v1_0.codec; + +import java.util.Arrays; +import java.util.List; + +import org.apache.qpid.server.bytebuffer.QpidByteBuffer; +import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException; +import org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry; +import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError; +import org.apache.qpid.test.utils.QpidTestCase; + +public class ValueHandlerTest extends QpidTestCase +{ + + private byte[] FORMAT_CODES = { + 0x00, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, + 0x60, 0x61, + 0x70, 0x71, 0x72, 0x73, 0x74, + (byte) 0x80, (byte) 0x81, (byte) 0x82, (byte) 0x83, (byte) 0x84, + (byte) 0x94, (byte) 0x98, + (byte) 0xA0, (byte) 0xA1, (byte) 0xA3, + (byte) 0xB0, (byte) 0xB1, (byte) 0xB3, + (byte) 0xC0, (byte) 0xC1, + (byte) 0xD0, (byte) 0xD1, + (byte) 0xE0, + (byte) 0xF0 + }; + + private static final AMQPDescribedTypeRegistry TYPE_REGISTRY = AMQPDescribedTypeRegistry.newInstance() + .registerTransportLayer() + .registerMessagingLayer() + .registerTransactionLayer() + .registerSecurityLayer(); + + private ValueHandler _valueHandle; + private ValueHandler _sectionValueHandler; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + _valueHandle = new ValueHandler(TYPE_REGISTRY); + _sectionValueHandler = new ValueHandler(TYPE_REGISTRY.getSectionDecoderRegistry()); + } + + public void testIncompleteValueParsingFormatCodeOnly() + { + for (byte b : FORMAT_CODES) + { + byte[] in = {b}; + performTest(b, in); + } + } + + public void testIncompleteValueParsingVariableOneFormatCodeOnlyAndSize() + { + byte[] variableOne = {(byte) 0xA0, (byte) 0xA1, (byte) 0xA3}; + for (byte b : variableOne) + { + byte[] in = {b, (byte) 1}; + performTest(b, in); + } + } + + public void testIncompleteValueParsingVariableFour() + { + byte[] variableFour = {(byte) 0xB0, (byte) 0xB1, (byte) 0xB3}; + for (byte b : variableFour) + { + byte[] in = {b, (byte) 0, (byte) 0, (byte) 0, (byte) 2}; + performTest(b, in); + } + } + + public void testIncompleteValueParsingCompoundOneOrArrayOne() + { + byte[] compoundOne = {(byte) 0xC0, (byte) 0xC1, (byte) 0xE0}; + for (byte b : compoundOne) + { + byte[] in = {b, (byte) 1}; + performTest(b, in); + } + } + + public void testIncompleteValueParsingCompoundFourOrArrayFour() + { + byte[] compoundFour = {(byte) 0xD0, (byte) 0xD1, (byte) 0xF0}; + for (byte b : compoundFour) + { + byte[] in = {b, (byte) 0, (byte) 0, (byte) 0, (byte) 1}; + performTest(b, in); + } + } + + + public void testIncompleteValueParsingCompoundOneWhenOnlySizeAndCountSpecified() + { + byte[] compoundOne = {(byte) 0xC0, (byte) 0xC1, (byte) 0xE0}; + for (byte b : compoundOne) + { + byte[] in = {b, (byte) 2, (byte) 1}; + performTest(b, in); + } + } + + public void testIncompleteValueParsingCompoundFourWhenOnlySizeAndCountSpecified() + { + byte[] compoundFour = {(byte) 0xD0, (byte) 0xD1, (byte) 0xF0}; + for (byte b : compoundFour) + { + byte[] in = {b, (byte) 0, (byte) 0, (byte) 0, (byte) 2, (byte) 0, (byte) 0, (byte) 0, (byte) 1}; + performTest(b, in); + } + } + + public void testIncompleteValueParsingArrayOneElementConstructor() + { + byte[] in = {(byte) 0xE0, (byte) 3, (byte) 1, 0x50}; + performTest((byte) 0xE0, in); + } + + public void testIncompleteValueParsingArrayOneElementConstructorWhenSizeIsWrong() + { + byte[] in = {(byte) 0xE0, (byte) 2, (byte) 1, 0x50, (byte) 1}; + performTest((byte) 0xE0, in); + } + + public void testIncompleteValueParsingArrayFourElementConstructor() + { + byte[] in = {(byte) 0xF0, (byte) 0, (byte) 0, (byte) 0, (byte) 2, (byte) 0, (byte) 0, (byte) 0, (byte) 1, 0x50}; + performTest((byte) 0xF0, in); + } + + public void testIncompleteSection() + { + byte[] in = { 0x00, 0x53, 0x75, (byte) 0xA0, 0x01, 0x00 }; + for (int i = in.length - 1; i > 1; --i) + { + byte[] newArray = new byte[i]; + System.arraycopy(in, 0, newArray, 0, i); + performSectionTest((byte) 0x00, newArray); + } + } + + private void performSectionTest(final byte type, final byte[] encodedBytes) + { + performTest(type, encodedBytes, _sectionValueHandler); + } + + private void performTest(final byte type, final byte[] encodedBytes) + { + performTest(type, encodedBytes, _valueHandle); + } + + private void performTest(final byte type, final byte[] encodedBytes, ValueHandler valueHandler) + { + QpidByteBuffer qbb = QpidByteBuffer.wrap(encodedBytes); + + try + { + valueHandler.parse(qbb); + fail(String.format("AmqpErrorException is expected for %#02x", type)); + } + catch (AmqpErrorException e) + { + assertEquals(String.format("Unexpected error code for %#02x", type), + AmqpError.DECODE_ERROR, + e.getError().getCondition()); + } + catch (Exception e) + { + fail(String.format("Unexpected exception for %#02x: %s", type, e)); + } + } +} http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/2402b637/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCMessageStore.java ---------------------------------------------------------------------- diff --git a/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCMessageStore.java b/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCMessageStore.java index 7aad22f..a30451d 100644 --- a/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCMessageStore.java +++ b/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCMessageStore.java @@ -964,7 +964,7 @@ public abstract class AbstractJDBCMessageStore implements MessageStore } return metaData; } - catch (IOException e) + catch (IOException | RuntimeException e) { throw new StoreException("Failed to stream metadata for message with id " + messageId, e); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
