You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by lq...@apache.org on 2017/09/29 12:32:08 UTC
[1/2] qpid-broker-j git commit: QPID-7932: [Java Broker,
AMQP 1.0] Improve Error handling for decoding invalid byte streams
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: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[2/2] qpid-broker-j git commit: QPID-7932: [Java Broker,
AMQP 1.0] Improve Error handling for decoding invalid byte streams
Posted by lq...@apache.org.
QPID-7932: [Java Broker, AMQP 1.0] Improve Error handling for decoding invalid byte streams
Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/2402b637
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/2402b637
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/2402b637
Branch: refs/heads/master
Commit: 2402b63796a0fb81455d6842669017676860e169
Parents: d4d408f
Author: Lorenz Quack <lq...@apache.org>
Authored: Fri Sep 29 12:40:10 2017 +0100
Committer: Lorenz Quack <lq...@apache.org>
Committed: Fri Sep 29 13:32:00 2017 +0100
----------------------------------------------------------------------
.../tuple/MessageMetaDataBinding.java | 2 +-
.../server/bytebuffer/QpidByteBufferUtils.java | 5 +
.../v1/MessageStoreSerializer_v1.java | 12 +-
.../protocol/v1_0/MessageMetaData_1_0.java | 5 +-
.../codec/AbstractCompositeTypeConstructor.java | 30 ++-
.../v1_0/codec/ArrayTypeConstructor.java | 18 +-
.../v1_0/codec/BinaryTypeConstructor.java | 18 +-
.../protocol/v1_0/codec/BooleanConstructor.java | 5 +-
.../v1_0/codec/ByteTypeConstructor.java | 13 +-
.../v1_0/codec/CharTypeConstructor.java | 6 +-
.../protocol/v1_0/codec/DecimalConstructor.java | 8 +-
.../v1_0/codec/DoubleTypeConstructor.java | 10 +-
.../v1_0/codec/FloatTypeConstructor.java | 12 +-
.../protocol/v1_0/codec/IntTypeConstructor.java | 12 +-
.../protocol/v1_0/codec/ListConstructor.java | 2 +-
.../v1_0/codec/LongTypeConstructor.java | 12 +-
.../protocol/v1_0/codec/MapConstructor.java | 28 +--
.../v1_0/codec/NullTypeConstructor.java | 2 +-
.../v1_0/codec/ShortTypeConstructor.java | 12 +-
.../v1_0/codec/SmallIntConstructor.java | 12 +-
.../v1_0/codec/SmallLongConstructor.java | 12 +-
.../v1_0/codec/SmallUIntConstructor.java | 12 +-
.../v1_0/codec/SmallULongConstructor.java | 12 +-
.../v1_0/codec/StringTypeConstructor.java | 33 ++--
.../v1_0/codec/SymbolTypeConstructor.java | 34 ++--
.../v1_0/codec/TimestampTypeConstructor.java | 8 +-
.../v1_0/codec/UByteTypeConstructor.java | 13 +-
.../v1_0/codec/UIntTypeConstructor.java | 13 +-
.../v1_0/codec/ULongTypeConstructor.java | 13 +-
.../v1_0/codec/UShortTypeConstructor.java | 14 +-
.../v1_0/codec/UUIDTypeConstructor.java | 9 +-
.../protocol/v1_0/codec/ValueHandler.java | 3 +-
.../v1_0/codec/ZeroListConstructor.java | 2 +-
.../v1_0/codec/ZeroUIntConstructor.java | 1 -
.../v1_0/codec/ZeroULongConstructor.java | 2 +-
.../protocol/v1_0/framing/FrameHandler.java | 3 +-
.../protocol/v1_0/messaging/SectionDecoder.java | 3 -
.../v1_0/messaging/SectionDecoderImpl.java | 8 -
.../v1_0/type/messaging/AbstractSection.java | 7 +
.../codec/AmqpValueSectionConstructor.java | 43 +++-
.../messaging/codec/DataSectionConstructor.java | 14 +-
.../codec/DescribedListSectionConstructor.java | 16 +-
.../codec/DescribedMapSectionConstructor.java | 14 +-
.../protocol/v1_0/codec/ValueHandlerTest.java | 196 +++++++++++++++++++
.../store/jdbc/AbstractJDBCMessageStore.java | 2 +-
45 files changed, 473 insertions(+), 238 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/2402b637/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/tuple/MessageMetaDataBinding.java
----------------------------------------------------------------------
diff --git a/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/tuple/MessageMetaDataBinding.java b/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/tuple/MessageMetaDataBinding.java
index 798b097..0fd3e44 100644
--- a/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/tuple/MessageMetaDataBinding.java
+++ b/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/tuple/MessageMetaDataBinding.java
@@ -71,7 +71,7 @@ public class MessageMetaDataBinding implements EntryBinding<StorableMessageMetaD
}
return metaData;
}
- catch (IOException e)
+ catch (IOException | RuntimeException e)
{
throw new StoreException(String.format("Unable to convert entry %s to metadata", entry));
}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/2402b637/broker-core/src/main/java/org/apache/qpid/server/bytebuffer/QpidByteBufferUtils.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/bytebuffer/QpidByteBufferUtils.java b/broker-core/src/main/java/org/apache/qpid/server/bytebuffer/QpidByteBufferUtils.java
index 57552a8..2592559 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/bytebuffer/QpidByteBufferUtils.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/bytebuffer/QpidByteBufferUtils.java
@@ -267,5 +267,10 @@ public class QpidByteBufferUtils
}
i++;
}
+
+ if (skipped != length)
+ {
+ throw new BufferUnderflowException();
+ }
}
}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/2402b637/broker-core/src/main/java/org/apache/qpid/server/store/serializer/v1/MessageStoreSerializer_v1.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/store/serializer/v1/MessageStoreSerializer_v1.java b/broker-core/src/main/java/org/apache/qpid/server/store/serializer/v1/MessageStoreSerializer_v1.java
index 9f0098a..c75b930 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/store/serializer/v1/MessageStoreSerializer_v1.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/store/serializer/v1/MessageStoreSerializer_v1.java
@@ -46,6 +46,7 @@ import org.apache.qpid.server.store.handler.DistributedTransactionHandler;
import org.apache.qpid.server.store.handler.MessageHandler;
import org.apache.qpid.server.store.handler.MessageInstanceHandler;
import org.apache.qpid.server.store.serializer.MessageStoreSerializer;
+import org.apache.qpid.server.util.ConnectionScopedRuntimeException;
@PluggableService
public class MessageStoreSerializer_v1 implements MessageStoreSerializer
@@ -307,8 +308,15 @@ public class MessageStoreSerializer_v1 implements MessageStoreSerializer
final MessageMetaDataType metaDataType =
MessageMetaDataTypeRegistry.fromOrdinal(metaData[0] & 0xff);
QpidByteBuffer buf = QpidByteBuffer.wrap(metaData, 1, metaData.length - 1);
- final StorableMessageMetaData storableMessageMetaData =
- metaDataType.createMetaData(Collections.singletonList(buf));
+ final StorableMessageMetaData storableMessageMetaData;
+ try
+ {
+ storableMessageMetaData = metaDataType.createMetaData(Collections.singletonList(buf));
+ }
+ catch (ConnectionScopedRuntimeException e)
+ {
+ throw new IllegalArgumentException("Could not deserialize message metadata", e);
+ }
buf.dispose();
final MessageHandle<StorableMessageMetaData> handle =
store.addMessage(storableMessageMetaData);
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/MessageMetaData_1_0.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/MessageMetaData_1_0.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/MessageMetaData_1_0.java
index 5b6d6b8..6d59a15 100755
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/MessageMetaData_1_0.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/MessageMetaData_1_0.java
@@ -438,6 +438,10 @@ public class MessageMetaData_1_0 implements StorableMessageMetaData
long contentSize = 0;
if (versionByte == 1)
{
+ if (!QpidByteBufferUtils.hasRemaining(bufs, 17))
+ {
+ throw new ConnectionScopedRuntimeException("Cannot decode stored message meta data.");
+ }
// we can discard the first byte
QpidByteBufferUtils.get(bufs);
arrivalTime = QpidByteBufferUtils.getLong(bufs);
@@ -479,7 +483,6 @@ public class MessageMetaData_1_0 implements StorableMessageMetaData
}
catch (AmqpErrorException e)
{
- //TODO
throw new ConnectionScopedRuntimeException(e);
}
}
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/codec/AbstractCompositeTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/AbstractCompositeTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/AbstractCompositeTypeConstructor.java
index c417b69..00a1252 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/AbstractCompositeTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/AbstractCompositeTypeConstructor.java
@@ -62,13 +62,13 @@ public abstract class AbstractCompositeTypeConstructor<T> implements DescribedTy
private T constructType() throws AmqpErrorException
{
+ int size;
final TypeConstructor typeConstructor = _valueHandler.readConstructor(_in);
+ long remaining = QpidByteBufferUtils.remaining(_in);
if (typeConstructor instanceof ListConstructor)
{
ListConstructor listConstructor = (ListConstructor) typeConstructor;
- int size;
- long remaining = QpidByteBufferUtils.remaining(_in);
- if (remaining < listConstructor.getSize())
+ if (remaining < listConstructor.getSize() * 2)
{
throw new AmqpErrorException(AmqpError.DECODE_ERROR,
String.format("Not sufficient data for deserialization of '%s'."
@@ -102,6 +102,7 @@ public abstract class AbstractCompositeTypeConstructor<T> implements DescribedTy
}
else if (typeConstructor instanceof ZeroListConstructor)
{
+ size = 0;
_count = 0;
}
else
@@ -110,7 +111,28 @@ public abstract class AbstractCompositeTypeConstructor<T> implements DescribedTy
String.format("Unexpected format when deserializing of '%s'",
getTypeName()));
}
- return AbstractCompositeTypeConstructor.this.construct(this);
+
+ final T constructedObject = AbstractCompositeTypeConstructor.this.construct(this);
+
+ long expectedRemaining = remaining - size;
+ long unconsumedBytes = QpidByteBufferUtils.remaining(_in) - expectedRemaining;
+ if(unconsumedBytes > 0)
+ {
+ final String msg =
+ String.format("%s incorrectly encoded, %d bytes remaining after decoding %d elements",
+ getTypeName(), unconsumedBytes, _count);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, msg);
+ }
+ else if (unconsumedBytes < 0)
+ {
+ final String msg = String.format(
+ "%s incorrectly encoded, %d bytes beyond provided size consumed after decoding %d elements",
+ getTypeName(),
+ -unconsumedBytes,
+ _count);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, msg);
+ }
+ return constructedObject;
}
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/codec/ArrayTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ArrayTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ArrayTypeConstructor.java
index 0545f76..a25f506 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ArrayTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ArrayTypeConstructor.java
@@ -51,19 +51,23 @@ public abstract class ArrayTypeConstructor implements TypeConstructor<Object[]>
{
rval.add(t.construct(in, handler));
}
- long unconsumedBytes = remaining - (QpidByteBufferUtils.remaining(in) + (long) size);
+ long expectedRemaining = remaining - size;
+ long unconsumedBytes = QpidByteBufferUtils.remaining(in) - expectedRemaining;
if(unconsumedBytes > 0)
{
- throw new AmqpErrorException(AmqpError.DECODE_ERROR,
- "Array incorrectly encoded, %d bytes remaining after decoding %d elements",
- unconsumedBytes, count);
+ final String msg = String.format("Array incorrectly encoded, %d bytes remaining after decoding %d elements",
+ unconsumedBytes,
+ count);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, msg);
}
else if (unconsumedBytes < 0)
{
- throw new AmqpErrorException(AmqpError.DECODE_ERROR,
- "Array incorrectly encoded, %d bytes beyond provided size consumed after decoding %d elements",
- -unconsumedBytes, count);
+ final String msg = String.format(
+ "Array incorrectly encoded, %d bytes beyond provided size consumed after decoding %d elements",
+ -unconsumedBytes,
+ count);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, msg);
}
if(rval.size() == 0)
{
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/codec/BinaryTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/BinaryTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/BinaryTypeConstructor.java
index 486bea0..622e9ea 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/BinaryTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/BinaryTypeConstructor.java
@@ -25,7 +25,7 @@ import java.util.List;
import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
import org.apache.qpid.server.protocol.v1_0.type.Binary;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class BinaryTypeConstructor extends VariableWidthTypeConstructor
{
@@ -49,7 +49,12 @@ public class BinaryTypeConstructor extends VariableWidthTypeConstructor
int size;
- if(getSize() == 1)
+ if (!QpidByteBufferUtils.hasRemaining(in, getSize()))
+ {
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct binary: insufficient input data");
+ }
+
+ if (getSize() == 1)
{
size = QpidByteBufferUtils.get(in) & 0xFF;
}
@@ -58,16 +63,13 @@ public class BinaryTypeConstructor extends VariableWidthTypeConstructor
size = QpidByteBufferUtils.getInt(in);
}
- if(!QpidByteBufferUtils.hasRemaining(in, size))
+ if (!QpidByteBufferUtils.hasRemaining(in, size))
{
- org.apache.qpid.server.protocol.v1_0.type.transport.Error error = new org.apache.qpid.server.protocol.v1_0.type.transport.Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct binary: insufficient input data");
- throw new AmqpErrorException(error);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct binary: insufficient input data");
}
byte[] data = new byte[size];
- QpidByteBufferUtils.get(in,data);
+ QpidByteBufferUtils.get(in, data);
return new Binary(data);
}
}
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/codec/BooleanConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/BooleanConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/BooleanConstructor.java
index 1d7310d..08431cd 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/BooleanConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/BooleanConstructor.java
@@ -62,10 +62,7 @@ public class BooleanConstructor
}
else
{
- org.apache.qpid.server.protocol.v1_0.type.transport.Error error = new Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct boolean: insufficient input data");
- throw new AmqpErrorException(error);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct boolean: insufficient input data");
}
}
};
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/codec/ByteTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ByteTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ByteTypeConstructor.java
index 2fa9e41..47213cd 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ByteTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ByteTypeConstructor.java
@@ -22,11 +22,10 @@ package org.apache.qpid.server.protocol.v1_0.codec;
import java.util.List;
-import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
-import org.apache.qpid.server.protocol.v1_0.type.*;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
-import org.apache.qpid.server.protocol.v1_0.type.transport.Error;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
+import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class ByteTypeConstructor implements TypeConstructor<Byte>
{
@@ -50,11 +49,7 @@ public class ByteTypeConstructor implements TypeConstructor<Byte>
}
else
{
- Error error = new Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct byte: insufficient input data");
- throw new AmqpErrorException(error);
-
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct byte: insufficient input data");
}
}
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/codec/CharTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/CharTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/CharTypeConstructor.java
index 6cce923..5f7a1ab 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/CharTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/CharTypeConstructor.java
@@ -52,11 +52,7 @@ public class CharTypeConstructor implements TypeConstructor<String>
}
else
{
- org.apache.qpid.server.protocol.v1_0.type.transport.Error error = new org.apache.qpid.server.protocol.v1_0.type.transport.Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct char: insufficient input data");
- throw new AmqpErrorException(error);
-
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct char: insufficient input data");
}
}
}
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/codec/DecimalConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/DecimalConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/DecimalConstructor.java
index d46f4aa..d7ae43f 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/DecimalConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/DecimalConstructor.java
@@ -25,7 +25,7 @@ import java.util.List;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public abstract class DecimalConstructor implements TypeConstructor<BigDecimal>
{
@@ -44,7 +44,7 @@ public abstract class DecimalConstructor implements TypeConstructor<BigDecimal>
}
else
{
- throw new AmqpErrorException(ConnectionError.FRAMING_ERROR, "Cannot construct decimal32: insufficient input data");
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct decimal32: insufficient input data");
}
return constructFrom32(val);
@@ -67,7 +67,7 @@ public abstract class DecimalConstructor implements TypeConstructor<BigDecimal>
}
else
{
- throw new AmqpErrorException(ConnectionError.FRAMING_ERROR, "Cannot construct decimal64: insufficient input data");
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct decimal64: insufficient input data");
}
return constructFrom64(val);
@@ -93,7 +93,7 @@ public abstract class DecimalConstructor implements TypeConstructor<BigDecimal>
}
else
{
- throw new AmqpErrorException(ConnectionError.FRAMING_ERROR, "Cannot construct decimal128: insufficient input data");
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct decimal128: insufficient input data");
}
return constructFrom128(high, low);
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/codec/DoubleTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/DoubleTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/DoubleTypeConstructor.java
index aba2d8c..aaaef75 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/DoubleTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/DoubleTypeConstructor.java
@@ -22,11 +22,10 @@ package org.apache.qpid.server.protocol.v1_0.codec;
import java.util.List;
+import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
-import org.apache.qpid.server.protocol.v1_0.type.transport.Error;
-import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class DoubleTypeConstructor implements TypeConstructor<Double>
{
@@ -51,10 +50,7 @@ public class DoubleTypeConstructor implements TypeConstructor<Double>
}
else
{
- Error error = new Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct double: insufficient input data");
- throw new AmqpErrorException(error);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct double: insufficient input data");
}
}
}
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/codec/FloatTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/FloatTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/FloatTypeConstructor.java
index 66be0d3..9c8c88e 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/FloatTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/FloatTypeConstructor.java
@@ -22,11 +22,10 @@ package org.apache.qpid.server.protocol.v1_0.codec;
import java.util.List;
-import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
-import org.apache.qpid.server.protocol.v1_0.type.*;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
-import org.apache.qpid.server.protocol.v1_0.type.transport.Error;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
+import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class FloatTypeConstructor implements TypeConstructor<Float>
{
@@ -51,10 +50,7 @@ public class FloatTypeConstructor implements TypeConstructor<Float>
}
else
{
- org.apache.qpid.server.protocol.v1_0.type.transport.Error error = new Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct float: insufficient input data");
- throw new AmqpErrorException(error);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct float: insufficient input data");
}
}
}
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/codec/IntTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/IntTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/IntTypeConstructor.java
index 69f3a25..8428e00 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/IntTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/IntTypeConstructor.java
@@ -22,10 +22,10 @@ package org.apache.qpid.server.protocol.v1_0.codec;
import java.util.List;
-import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
-import org.apache.qpid.server.protocol.v1_0.type.*;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
+import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class IntTypeConstructor implements TypeConstructor<Integer>
{
@@ -50,11 +50,7 @@ public class IntTypeConstructor implements TypeConstructor<Integer>
}
else
{
- org.apache.qpid.server.protocol.v1_0.type.transport.Error error = new org.apache.qpid.server.protocol.v1_0.type.transport.Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct int: insufficient input data");
- throw new AmqpErrorException(error);
-
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct int: insufficient input data");
}
}
}
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/codec/ListConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ListConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ListConstructor.java
index 87011d2..9c9f169 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ListConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ListConstructor.java
@@ -41,7 +41,7 @@ public class ListConstructor extends VariableWidthTypeConstructor<List>
int size;
int count;
long remaining = QpidByteBufferUtils.remaining(in);
- if (remaining < getSize())
+ if (remaining < getSize() * 2)
{
throw new AmqpErrorException(AmqpError.DECODE_ERROR,
String.format("Not sufficient data for deserialization of 'list'."
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/codec/LongTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/LongTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/LongTypeConstructor.java
index 2b44607..70c8400 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/LongTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/LongTypeConstructor.java
@@ -22,10 +22,10 @@ package org.apache.qpid.server.protocol.v1_0.codec;
import java.util.List;
-import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
-import org.apache.qpid.server.protocol.v1_0.type.*;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
+import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class LongTypeConstructor implements TypeConstructor<Long>
{
@@ -50,11 +50,7 @@ public class LongTypeConstructor implements TypeConstructor<Long>
}
else
{
- org.apache.qpid.server.protocol.v1_0.type.transport.Error error = new org.apache.qpid.server.protocol.v1_0.type.transport.Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct long: insufficient input data");
- throw new AmqpErrorException(error);
-
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct long: insufficient input data");
}
}
}
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/codec/MapConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/MapConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/MapConstructor.java
index 4c791e8..e04480a 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/MapConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/MapConstructor.java
@@ -42,15 +42,16 @@ public class MapConstructor extends VariableWidthTypeConstructor<Map>
return construct(in, handler, Object.class, Object.class);
}
- public <T,S> Map<T, S> construct(final List<QpidByteBuffer> in, final ValueHandler handler,
- Class<T> keyType,
- Class<S> valueType) throws AmqpErrorException
+ public <T, S> Map<T, S> construct(final List<QpidByteBuffer> in,
+ final ValueHandler handler,
+ Class<T> keyType,
+ Class<S> valueType) throws AmqpErrorException
{
int size;
int count;
long remaining = QpidByteBufferUtils.remaining(in);
- if (remaining < getSize())
+ if (remaining < getSize() * 2)
{
throw new AmqpErrorException(AmqpError.DECODE_ERROR,
String.format("Not sufficient data for deserialization of 'map'."
@@ -59,7 +60,7 @@ public class MapConstructor extends VariableWidthTypeConstructor<Map>
remaining));
}
- if(getSize() == 1)
+ if (getSize() == 1)
{
size = QpidByteBufferUtils.get(in) & 0xFF;
count = QpidByteBufferUtils.get(in) & 0xFF;
@@ -83,12 +84,12 @@ public class MapConstructor extends VariableWidthTypeConstructor<Map>
}
- private <T, S> Map<T,S> construct(final List<QpidByteBuffer> in,
- final ValueHandler handler,
- final int size,
- final int count,
- Class<T> keyType,
- Class<S> valueType)
+ private <T, S> Map<T, S> construct(final List<QpidByteBuffer> in,
+ final ValueHandler handler,
+ final int size,
+ final int count,
+ Class<T> keyType,
+ Class<S> valueType)
throws AmqpErrorException
{
@@ -102,7 +103,7 @@ public class MapConstructor extends VariableWidthTypeConstructor<Map>
Map<T, S> map = new LinkedHashMap<>(count);
final int mapSize = count / 2;
- for(int i = 0; i < mapSize; i++)
+ for (int i = 0; i < mapSize; i++)
{
Object key = handler.parse(in);
if (key != null && !keyType.isAssignableFrom(key.getClass()))
@@ -123,7 +124,7 @@ public class MapConstructor extends VariableWidthTypeConstructor<Map>
}
Object oldValue;
- if ((oldValue = map.put((T)key, (S)value)) != null)
+ if ((oldValue = map.put((T) key, (S) value)) != null)
{
String message = String.format("Map cannot have duplicate keys: %s has values (%s, %s)",
key,
@@ -131,7 +132,6 @@ public class MapConstructor extends VariableWidthTypeConstructor<Map>
value);
throw new AmqpErrorException(AmqpError.DECODE_ERROR, message);
}
-
}
return map;
}
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/codec/NullTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/NullTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/NullTypeConstructor.java
index 6b49222..b0620ca 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/NullTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/NullTypeConstructor.java
@@ -33,7 +33,7 @@ class NullTypeConstructor implements TypeConstructor<Void>
}
@Override
- public Void construct(final List<QpidByteBuffer> in, final ValueHandler handler) throws AmqpErrorException
+ public Void construct(final List<QpidByteBuffer> in, final ValueHandler handler)
{
return null;
}
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/codec/ShortTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ShortTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ShortTypeConstructor.java
index 396911a..30e7efb 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ShortTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ShortTypeConstructor.java
@@ -22,10 +22,10 @@ package org.apache.qpid.server.protocol.v1_0.codec;
import java.util.List;
-import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
-import org.apache.qpid.server.protocol.v1_0.type.*;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
+import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class ShortTypeConstructor implements TypeConstructor<Short>
{
@@ -50,11 +50,7 @@ public class ShortTypeConstructor implements TypeConstructor<Short>
}
else
{
- org.apache.qpid.server.protocol.v1_0.type.transport.Error error = new org.apache.qpid.server.protocol.v1_0.type.transport.Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct short: insufficient input data");
- throw new AmqpErrorException(error);
-
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct short: insufficient input data");
}
}
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/codec/SmallIntConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallIntConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallIntConstructor.java
index 5098b34..41f462e 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallIntConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallIntConstructor.java
@@ -21,11 +21,10 @@ package org.apache.qpid.server.protocol.v1_0.codec;
import java.util.List;
+import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
-import org.apache.qpid.server.protocol.v1_0.type.transport.Error;
-import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class SmallIntConstructor implements TypeConstructor<Integer>
{
@@ -44,17 +43,14 @@ public class SmallIntConstructor implements TypeConstructor<Integer>
@Override
public Integer construct(final List<QpidByteBuffer> in, final ValueHandler handler) throws AmqpErrorException
{
- if(QpidByteBufferUtils.hasRemaining(in))
+ if (QpidByteBufferUtils.hasRemaining(in))
{
byte b = QpidByteBufferUtils.get(in);
return (int) b;
}
else
{
- Error error = new Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct int: insufficient input data");
- throw new AmqpErrorException(error);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct int: insufficient input data");
}
}
}
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/codec/SmallLongConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallLongConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallLongConstructor.java
index 0bf79d7..44741e1 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallLongConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallLongConstructor.java
@@ -21,11 +21,10 @@ package org.apache.qpid.server.protocol.v1_0.codec;
import java.util.List;
+import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
-import org.apache.qpid.server.protocol.v1_0.type.transport.Error;
-import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class SmallLongConstructor implements TypeConstructor<Long>
{
@@ -44,17 +43,14 @@ public class SmallLongConstructor implements TypeConstructor<Long>
@Override
public Long construct(final List<QpidByteBuffer> in, final ValueHandler handler) throws AmqpErrorException
{
- if(QpidByteBufferUtils.hasRemaining(in))
+ if (QpidByteBufferUtils.hasRemaining(in))
{
byte b = QpidByteBufferUtils.get(in);
return (long) b;
}
else
{
- Error error = new Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct long: insufficient input data");
- throw new AmqpErrorException(error);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct long: insufficient input data");
}
}
}
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/codec/SmallUIntConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallUIntConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallUIntConstructor.java
index 32df052..b080814 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallUIntConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallUIntConstructor.java
@@ -20,12 +20,11 @@ package org.apache.qpid.server.protocol.v1_0.codec;
import java.util.List;
+import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
import org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
-import org.apache.qpid.server.protocol.v1_0.type.transport.Error;
-import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class SmallUIntConstructor implements TypeConstructor<UnsignedInteger>
{
@@ -45,17 +44,14 @@ public class SmallUIntConstructor implements TypeConstructor<UnsignedInteger>
public UnsignedInteger construct(final List<QpidByteBuffer> in, final ValueHandler handler)
throws AmqpErrorException
{
- if(QpidByteBufferUtils.hasRemaining(in))
+ if (QpidByteBufferUtils.hasRemaining(in))
{
byte b = QpidByteBufferUtils.get(in);
return UnsignedInteger.valueOf(((int) b) & 0xff);
}
else
{
- Error error = new Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct uint: insufficient input data");
- throw new AmqpErrorException(error);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct uint: insufficient input data");
}
}
}
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/codec/SmallULongConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallULongConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallULongConstructor.java
index 845f745..9e34ea9 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallULongConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SmallULongConstructor.java
@@ -21,12 +21,11 @@ package org.apache.qpid.server.protocol.v1_0.codec;
import java.util.List;
+import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
import org.apache.qpid.server.protocol.v1_0.type.UnsignedLong;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
-import org.apache.qpid.server.protocol.v1_0.type.transport.Error;
-import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class SmallULongConstructor implements TypeConstructor<UnsignedLong>
{
@@ -45,17 +44,14 @@ public class SmallULongConstructor implements TypeConstructor<UnsignedLong>
@Override
public UnsignedLong construct(final List<QpidByteBuffer> in, final ValueHandler handler) throws AmqpErrorException
{
- if(QpidByteBufferUtils.hasRemaining(in))
+ if (QpidByteBufferUtils.hasRemaining(in))
{
byte b = QpidByteBufferUtils.get(in);
return UnsignedLong.valueOf(((long) b) & 0xffL);
}
else
{
- Error error = new Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct ulong: insufficient input data");
- throw new AmqpErrorException(error);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct ulong: insufficient input data");
}
}
}
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/codec/StringTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/StringTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/StringTypeConstructor.java
index 3a93f29..b1e5b42 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/StringTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/StringTypeConstructor.java
@@ -28,7 +28,7 @@ import java.util.List;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class StringTypeConstructor extends VariableWidthTypeConstructor<String>
{
@@ -52,7 +52,7 @@ public class StringTypeConstructor extends VariableWidthTypeConstructor<String>
QpidByteBuffer dup = in.duplicate();
try
{
- dup.limit(dup.position()+size);
+ dup.limit(dup.position() + size);
CharBuffer charBuf = dup.decode(UTF_8);
String str = charBuf.toString();
@@ -61,9 +61,14 @@ public class StringTypeConstructor extends VariableWidthTypeConstructor<String>
return str;
}
- catch(IllegalArgumentException e)
+ catch (IllegalArgumentException e)
{
- throw new IllegalArgumentException("position: " + dup.position() + "size: " + size + " capacity: " + dup.capacity());
+ throw new IllegalArgumentException("position: "
+ + dup.position()
+ + "size: "
+ + size
+ + " capacity: "
+ + dup.capacity());
}
finally
{
@@ -76,7 +81,12 @@ public class StringTypeConstructor extends VariableWidthTypeConstructor<String>
{
int size;
- if(getSize() == 1)
+ if (!QpidByteBufferUtils.hasRemaining(in, getSize()))
+ {
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct string: insufficient input data");
+ }
+
+ if (getSize() == 1)
{
size = QpidByteBufferUtils.get(in) & 0xFF;
}
@@ -85,20 +95,17 @@ public class StringTypeConstructor extends VariableWidthTypeConstructor<String>
size = QpidByteBufferUtils.getInt(in);
}
- if(!QpidByteBufferUtils.hasRemaining(in, size))
+ if (!QpidByteBufferUtils.hasRemaining(in, size))
{
- org.apache.qpid.server.protocol.v1_0.type.transport.Error error = new org.apache.qpid.server.protocol.v1_0.type.transport.Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct string: insufficient input data");
- throw new AmqpErrorException(error);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct string: insufficient input data");
}
- for(int i = 0; i<in.size(); i++)
+ for (int i = 0; i < in.size(); i++)
{
QpidByteBuffer buf = in.get(i);
- if(buf.hasRemaining())
+ if (buf.hasRemaining())
{
- if(buf.remaining() >= size)
+ if (buf.remaining() >= size)
{
return constructFromSingleBuffer(buf, 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/codec/SymbolTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SymbolTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SymbolTypeConstructor.java
index c58a52f..09f467f 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SymbolTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/SymbolTypeConstructor.java
@@ -26,11 +26,11 @@ import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
import org.apache.qpid.server.protocol.v1_0.type.Symbol;
-import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class SymbolTypeConstructor extends VariableWidthTypeConstructor<Symbol>
{
@@ -55,7 +55,7 @@ public class SymbolTypeConstructor extends VariableWidthTypeConstructor<Symbol>
BinaryString binaryStr;
if (in.hasArray())
{
- binaryStr = new BinaryString(in.array(), in.arrayOffset()+in.position(), size);
+ binaryStr = new BinaryString(in.array(), in.arrayOffset() + in.position(), size);
}
else
{
@@ -67,10 +67,10 @@ public class SymbolTypeConstructor extends VariableWidthTypeConstructor<Symbol>
}
Symbol symbolVal = SYMBOL_MAP.get(binaryStr);
- if(symbolVal == null)
+ if (symbolVal == null)
{
QpidByteBuffer dup = in.duplicate();
- dup.limit(in.position()+size);
+ dup.limit(in.position() + size);
CharBuffer charBuf = dup.decode(ASCII);
dup.dispose();
@@ -83,7 +83,7 @@ public class SymbolTypeConstructor extends VariableWidthTypeConstructor<Symbol>
}
else
{
- in.position(in.position()+size);
+ in.position(in.position() + size);
}
return symbolVal;
@@ -95,7 +95,12 @@ public class SymbolTypeConstructor extends VariableWidthTypeConstructor<Symbol>
int size;
- if(getSize() == 1)
+ if (!QpidByteBufferUtils.hasRemaining(in, getSize()))
+ {
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct symbol: insufficient input data");
+ }
+
+ if (getSize() == 1)
{
size = QpidByteBufferUtils.get(in) & 0xFF;
}
@@ -104,20 +109,17 @@ public class SymbolTypeConstructor extends VariableWidthTypeConstructor<Symbol>
size = QpidByteBufferUtils.getInt(in);
}
- if(!QpidByteBufferUtils.hasRemaining(in, size))
+ if (!QpidByteBufferUtils.hasRemaining(in, size))
{
- org.apache.qpid.server.protocol.v1_0.type.transport.Error error = new org.apache.qpid.server.protocol.v1_0.type.transport.Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct symbol: insufficient input data");
- throw new AmqpErrorException(error);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct symbol: insufficient input data");
}
- for(int i = 0; i<in.size(); i++)
+ for (int i = 0; i < in.size(); i++)
{
QpidByteBuffer buf = in.get(i);
- if(buf.hasRemaining())
+ if (buf.hasRemaining())
{
- if(buf.remaining() >= size)
+ if (buf.remaining() >= size)
{
return constructFromSingleBuffer(buf, size);
}
@@ -130,7 +132,7 @@ public class SymbolTypeConstructor extends VariableWidthTypeConstructor<Symbol>
final BinaryString binaryStr = new BinaryString(data);
Symbol symbolVal = SYMBOL_MAP.get(binaryStr);
- if(symbolVal == null)
+ if (symbolVal == null)
{
symbolVal = Symbol.valueOf(new String(data, ASCII));
SYMBOL_MAP.putIfAbsent(binaryStr, symbolVal);
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/codec/TimestampTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/TimestampTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/TimestampTypeConstructor.java
index a76ae6f..eae7282 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/TimestampTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/TimestampTypeConstructor.java
@@ -26,7 +26,7 @@ import java.util.List;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class TimestampTypeConstructor implements TypeConstructor<Date>
{
@@ -52,11 +52,7 @@ public class TimestampTypeConstructor implements TypeConstructor<Date>
}
else
{
- org.apache.qpid.server.protocol.v1_0.type.transport.Error error = new org.apache.qpid.server.protocol.v1_0.type.transport.Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct timestamp: insufficient input data");
- throw new AmqpErrorException(error);
-
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct timestamp: insufficient input data");
}
}
}
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/codec/UByteTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UByteTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UByteTypeConstructor.java
index d03668c..e9a2bc5 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UByteTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UByteTypeConstructor.java
@@ -22,11 +22,11 @@ package org.apache.qpid.server.protocol.v1_0.codec;
import java.util.List;
-import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
-import org.apache.qpid.server.protocol.v1_0.type.*;
-import org.apache.qpid.server.protocol.v1_0.type.transport.Error;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
+import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
+import org.apache.qpid.server.protocol.v1_0.type.UnsignedByte;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class UByteTypeConstructor implements TypeConstructor<UnsignedByte>
{
@@ -52,10 +52,7 @@ public class UByteTypeConstructor implements TypeConstructor<UnsignedByte>
}
else
{
- Error error = new Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct ubyte: insufficient input data");
- throw new AmqpErrorException(error);
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct ubyte: insufficient input data");
}
}
}
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/codec/UIntTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UIntTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UIntTypeConstructor.java
index 700817d..f8d4c21 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UIntTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UIntTypeConstructor.java
@@ -22,10 +22,11 @@ package org.apache.qpid.server.protocol.v1_0.codec;
import java.util.List;
-import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
-import org.apache.qpid.server.protocol.v1_0.type.*;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
+import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
+import org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class UIntTypeConstructor implements TypeConstructor<UnsignedInteger>
{
@@ -52,11 +53,7 @@ public class UIntTypeConstructor implements TypeConstructor<UnsignedInteger>
}
else
{
- org.apache.qpid.server.protocol.v1_0.type.transport.Error error = new org.apache.qpid.server.protocol.v1_0.type.transport.Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct uint: insufficient input data");
- throw new AmqpErrorException(error);
-
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct uint: insufficient input data");
}
}
}
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/codec/ULongTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ULongTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ULongTypeConstructor.java
index dbd606f..5a71935 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ULongTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ULongTypeConstructor.java
@@ -22,10 +22,11 @@ package org.apache.qpid.server.protocol.v1_0.codec;
import java.util.List;
-import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
-import org.apache.qpid.server.protocol.v1_0.type.*;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
+import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
+import org.apache.qpid.server.protocol.v1_0.type.UnsignedLong;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class ULongTypeConstructor implements TypeConstructor<UnsignedLong>
{
@@ -53,11 +54,7 @@ public class ULongTypeConstructor implements TypeConstructor<UnsignedLong>
}
else
{
- org.apache.qpid.server.protocol.v1_0.type.transport.Error error = new org.apache.qpid.server.protocol.v1_0.type.transport.Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct ulong: insufficient input data");
- throw new AmqpErrorException(error);
-
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct ulong: insufficient input data");
}
}
}
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/codec/UShortTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UShortTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UShortTypeConstructor.java
index b22790b..8174d5b 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UShortTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UShortTypeConstructor.java
@@ -22,11 +22,11 @@ package org.apache.qpid.server.protocol.v1_0.codec;
import java.util.List;
-import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
-import org.apache.qpid.server.protocol.v1_0.type.*;
-import org.apache.qpid.server.protocol.v1_0.type.transport.Error;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
+import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
+import org.apache.qpid.server.protocol.v1_0.type.UnsignedShort;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class UShortTypeConstructor implements TypeConstructor<UnsignedShort>
{
@@ -52,11 +52,7 @@ public class UShortTypeConstructor implements TypeConstructor<UnsignedShort>
}
else
{
- org.apache.qpid.server.protocol.v1_0.type.transport.Error error = new Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct ushort: insufficient input data");
- throw new AmqpErrorException(error);
-
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct ushort: insufficient input data");
}
}
}
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/codec/UUIDTypeConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UUIDTypeConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UUIDTypeConstructor.java
index 4bff5c0..ce247fd 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UUIDTypeConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UUIDTypeConstructor.java
@@ -26,8 +26,7 @@ import java.util.UUID;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
-import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
-import org.apache.qpid.server.protocol.v1_0.type.transport.Error;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
public class UUIDTypeConstructor implements TypeConstructor<UUID>
{
@@ -54,11 +53,7 @@ public class UUIDTypeConstructor implements TypeConstructor<UUID>
}
else
{
- org.apache.qpid.server.protocol.v1_0.type.transport.Error error = new Error();
- error.setCondition(ConnectionError.FRAMING_ERROR);
- error.setDescription("Cannot construct UUID: insufficient input data");
- throw new AmqpErrorException(error);
-
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct UUID: insufficient input data");
}
}
}
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/codec/ValueHandler.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ValueHandler.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ValueHandler.java
index 56347f6..b7959e1 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ValueHandler.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ValueHandler.java
@@ -32,7 +32,7 @@ import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
public class ValueHandler implements DescribedTypeConstructorRegistry.Source
{
- private static final byte DESCRIBED_TYPE = (byte)0;
+ public static final byte DESCRIBED_TYPE = (byte)0;
private final DescribedTypeConstructorRegistry _describedTypeConstructorRegistry;
@@ -91,6 +91,7 @@ public class ValueHandler implements DescribedTypeConstructorRegistry.Source
{
return parse(new ArrayList<>(Arrays.asList(in)));
}
+
public Object parse(final List<QpidByteBuffer> in) throws AmqpErrorException
{
TypeConstructor constructor = readConstructor(in);
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/codec/ZeroListConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ZeroListConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ZeroListConstructor.java
index ae62241..4916538 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ZeroListConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ZeroListConstructor.java
@@ -34,7 +34,7 @@ class ZeroListConstructor implements TypeConstructor<List>
}
@Override
- public List construct(final List<QpidByteBuffer> in, final ValueHandler handler) throws AmqpErrorException
+ public List construct(final List<QpidByteBuffer> in, final ValueHandler handler)
{
return Collections.EMPTY_LIST;
}
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/codec/ZeroUIntConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ZeroUIntConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ZeroUIntConstructor.java
index 054ce8d..b83bf12 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ZeroUIntConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ZeroUIntConstructor.java
@@ -35,7 +35,6 @@ class ZeroUIntConstructor implements TypeConstructor<UnsignedInteger>
@Override
public UnsignedInteger construct(final List<QpidByteBuffer> in, final ValueHandler handler)
- throws AmqpErrorException
{
return UnsignedInteger.ZERO;
}
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/codec/ZeroULongConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ZeroULongConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ZeroULongConstructor.java
index 521da99..cdd086c 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ZeroULongConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/ZeroULongConstructor.java
@@ -34,7 +34,7 @@ class ZeroULongConstructor implements TypeConstructor<UnsignedLong>
}
@Override
- public UnsignedLong construct(final List<QpidByteBuffer> in, final ValueHandler handler) throws AmqpErrorException
+ public UnsignedLong construct(final List<QpidByteBuffer> in, final ValueHandler handler)
{
return UnsignedLong.ZERO;
}
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/framing/FrameHandler.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/framing/FrameHandler.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/framing/FrameHandler.java
index baebf51..523aec1 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/framing/FrameHandler.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/framing/FrameHandler.java
@@ -34,6 +34,7 @@ import org.apache.qpid.server.protocol.v1_0.codec.ProtocolHandler;
import org.apache.qpid.server.protocol.v1_0.codec.ValueHandler;
import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
import org.apache.qpid.server.protocol.v1_0.type.ErrorCondition;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
import org.apache.qpid.server.protocol.v1_0.type.transport.ChannelFrameBody;
import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
import org.apache.qpid.server.protocol.v1_0.type.transport.Error;
@@ -213,7 +214,7 @@ public class FrameHandler implements ProtocolHandler
}
LOGGER.warn("Unexpected exception handling frame", e);
// This exception is unexpected. The up layer should handle error condition gracefully
- _connectionHandler.handleError(this.createError(ConnectionError.CONNECTION_FORCED, e.toString()));
+ _connectionHandler.handleError(this.createError(AmqpError.INTERNAL_ERROR, e.toString()));
}
return this;
}
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/messaging/SectionDecoder.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/messaging/SectionDecoder.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/messaging/SectionDecoder.java
index d50162d..34d97e4 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/messaging/SectionDecoder.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/messaging/SectionDecoder.java
@@ -28,8 +28,5 @@ import org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSect
public interface SectionDecoder
{
-
List<EncodingRetainingSection<?>> parseAll(List<QpidByteBuffer> buf) throws AmqpErrorException;
-
- EncodingRetainingSection<?> readSection(List<QpidByteBuffer> buf) throws AmqpErrorException;
}
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/messaging/SectionDecoderImpl.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/messaging/SectionDecoderImpl.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/messaging/SectionDecoderImpl.java
index 7b9f742..8c327eb 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/messaging/SectionDecoderImpl.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/messaging/SectionDecoderImpl.java
@@ -65,12 +65,4 @@ public class SectionDecoderImpl implements SectionDecoder
return obj;
}
-
-
- @Override
- public EncodingRetainingSection<?> readSection(List<QpidByteBuffer> buf) throws AmqpErrorException
- {
- return (EncodingRetainingSection<?>) _valueHandler.parse(buf);
- }
-
}
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/AbstractSection.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/AbstractSection.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/AbstractSection.java
index ce284f1..c6a7be9 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/AbstractSection.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/AbstractSection.java
@@ -32,6 +32,7 @@ import org.apache.qpid.server.protocol.v1_0.messaging.SectionEncoder;
import org.apache.qpid.server.protocol.v1_0.messaging.SectionEncoderImpl;
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.server.util.ConnectionScopedRuntimeException;
public abstract class AbstractSection<T, S extends NonEncodingRetainingSection<T>> implements EncodingRetainingSection<T>
@@ -178,6 +179,12 @@ public abstract class AbstractSection<T, S extends NonEncodingRetainingSection<T
originalPositions[i] = input.get(i).position();
}
int describedByte = QpidByteBufferUtils.get(input);
+ if (describedByte != ValueHandler.DESCRIBED_TYPE)
+ {
+ throw new ConnectionScopedRuntimeException("Cannot decode section",
+ new AmqpErrorException(AmqpError.DECODE_ERROR,
+ "Not a described type."));
+ }
ValueHandler handler = new ValueHandler(TYPE_REGISTRY);
try
{
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/AmqpValueSectionConstructor.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/AmqpValueSectionConstructor.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/AmqpValueSectionConstructor.java
index 274a2aa..1af86b8 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/AmqpValueSectionConstructor.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/codec/AmqpValueSectionConstructor.java
@@ -26,15 +26,16 @@ package org.apache.qpid.server.protocol.v1_0.type.messaging.codec;
import java.util.List;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
import org.apache.qpid.server.protocol.v1_0.codec.DescribedTypeConstructor;
import org.apache.qpid.server.protocol.v1_0.codec.DescribedTypeConstructorRegistry;
-import org.apache.qpid.server.bytebuffer.QpidByteBufferUtils;
import org.apache.qpid.server.protocol.v1_0.codec.TypeConstructor;
import org.apache.qpid.server.protocol.v1_0.codec.ValueHandler;
import org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException;
import org.apache.qpid.server.protocol.v1_0.type.Symbol;
import org.apache.qpid.server.protocol.v1_0.type.UnsignedLong;
import org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection;
+import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
public class AmqpValueSectionConstructor implements DescribedTypeConstructor<AmqpValueSection>
@@ -83,9 +84,13 @@ public class AmqpValueSectionConstructor implements DescribedTypeConstructor<Amq
@Override
protected void skipValue(final List<QpidByteBuffer> in) throws AmqpErrorException
{
+ if (!QpidByteBufferUtils.hasRemaining(in))
+ {
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Insufficient data to decode AMQP value section.");
+ }
byte formatCode = QpidByteBufferUtils.get(in);
- if (formatCode == 0)
+ if (formatCode == ValueHandler.DESCRIBED_TYPE)
{
// This is only valid if the described value is not an array
skipValue(in);
@@ -93,39 +98,57 @@ public class AmqpValueSectionConstructor implements DescribedTypeConstructor<Amq
}
else
{
+ final int skipLength;
int category = (formatCode >> 4) & 0x0F;
switch (category)
{
case 0x04:
+ skipLength = 0;
break;
case 0x05:
- QpidByteBufferUtils.skip(in, 1);
+ skipLength = 1;
break;
case 0x06:
- QpidByteBufferUtils.skip(in, 2);
+ skipLength = 2;
break;
case 0x07:
- QpidByteBufferUtils.skip(in, 4);
+ skipLength = 4;
break;
case 0x08:
- QpidByteBufferUtils.skip(in, 8);
+ skipLength = 8;
break;
case 0x09:
- QpidByteBufferUtils.skip(in, 16);
+ skipLength = 16;
break;
case 0x0a:
case 0x0c:
case 0x0e:
- QpidByteBufferUtils.skip(in, ((int) QpidByteBufferUtils.get(in)) & 0xFF);
+ if (!QpidByteBufferUtils.hasRemaining(in))
+ {
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR,
+ "Insufficient data to decode AMQP value section.");
+ }
+ skipLength = ((int) QpidByteBufferUtils.get(in)) & 0xFF;
break;
case 0x0b:
case 0x0d:
case 0x0f:
- QpidByteBufferUtils.skip(in, QpidByteBufferUtils.getInt(in));
+ if (!QpidByteBufferUtils.hasRemaining(in, 4))
+ {
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR,
+ "Insufficient data to decode AMQP value section.");
+ }
+ skipLength = QpidByteBufferUtils.getInt(in);
break;
default:
- throw new AmqpErrorException(ConnectionError.FRAMING_ERROR, "Unknown type");
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Unknown type");
+ }
+ if (!QpidByteBufferUtils.hasRemaining(in, skipLength))
+ {
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR,
+ "Insufficient data to decode AMQP value section.");
}
+ QpidByteBufferUtils.skip(in,skipLength);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org