diff options
| author | Robert Godfrey <rgodfrey@apache.org> | 2014-10-27 13:51:59 +0000 |
|---|---|---|
| committer | Robert Godfrey <rgodfrey@apache.org> | 2014-10-27 13:51:59 +0000 |
| commit | a1d58191d8b393f4eb7a2a1691572ef1b5aa9e8f (patch) | |
| tree | 452c0ef6fba936b9910ed54c034e4ecfccfc1a01 /qpid/java/common/src/main | |
| parent | 5db8a7db8abcb70c75647642cd9d19331fb6839c (diff) | |
| download | qpid-python-a1d58191d8b393f4eb7a2a1691572ef1b5aa9e8f.tar.gz | |
QPID-6189 : [Java Common] fix stack overflow bug when frame is broken into thousands of reads/writes
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1634539 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/common/src/main')
| -rw-r--r-- | qpid/java/common/src/main/java/org/apache/qpid/codec/AMQDecoder.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/codec/AMQDecoder.java b/qpid/java/common/src/main/java/org/apache/qpid/codec/AMQDecoder.java index 9d98168687..9bafc30ebc 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/codec/AMQDecoder.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/codec/AMQDecoder.java @@ -47,6 +47,7 @@ import org.apache.qpid.protocol.AMQConstant; */ public abstract class AMQDecoder<T extends MethodProcessor> { + private static final int MAX_BUFFERS_LIMIT = 10; private final T _methodProcessor; /** Holds the protocol initiation decoder. */ @@ -298,6 +299,25 @@ public abstract class AMQDecoder<T extends MethodProcessor> _remainingBufs.add(new ByteArrayInputStream(remaining)); } } + + if(_remainingBufs.size() > MAX_BUFFERS_LIMIT) + { + int totalSize = 0; + for(ByteArrayInputStream stream : _remainingBufs) + { + totalSize += stream.available(); + } + + byte[] completeBuffer = new byte[totalSize]; + int pos = 0; + for(ByteArrayInputStream stream : _remainingBufs) + { + pos += stream.read(completeBuffer, pos, stream.available()); + } + + _remainingBufs.clear(); + _remainingBufs.add(new ByteArrayInputStream(completeBuffer)); + } } } } |
