From commits-return-48441-archive-asf-public=cust-asf.ponee.io@qpid.apache.org Tue Jun 18 11:14:18 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 0059118077F for ; Tue, 18 Jun 2019 13:14:17 +0200 (CEST) Received: (qmail 957 invoked by uid 500); 18 Jun 2019 11:14:17 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 860 invoked by uid 99); 18 Jun 2019 11:14:17 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Jun 2019 11:14:17 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 1F46B87AD9; Tue, 18 Jun 2019 11:14:17 +0000 (UTC) Date: Tue, 18 Jun 2019 11:14:19 +0000 To: "commits@qpid.apache.org" Subject: [qpid-broker-j] 02/04: QPID-8316: [Broker-J] Message validation should not store decoded headers in heap MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: orudyy@apache.org In-Reply-To: <156085645702.7420.4274701292756129917@gitbox.apache.org> References: <156085645702.7420.4274701292756129917@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: qpid-broker-j X-Git-Refname: refs/heads/7.0.x X-Git-Reftype: branch X-Git-Rev: 660363ac44a0220cbf4c3ed0f3f09c00d5428db4 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20190618111417.1F46B87AD9@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. orudyy pushed a commit to branch 7.0.x in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git commit 660363ac44a0220cbf4c3ed0f3f09c00d5428db4 Author: Alex Rudyy AuthorDate: Fri Jun 14 12:43:05 2019 +0100 QPID-8316: [Broker-J] Message validation should not store decoded headers in heap (cherry picked from commit ee225cdada7be63ea5ae7bfdaecc635bbabc3d5a) --- .../qpid/server/protocol/v0_8/FieldTable.java | 63 ++++++++++++---------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/broker-core/src/main/java/org/apache/qpid/server/protocol/v0_8/FieldTable.java b/broker-core/src/main/java/org/apache/qpid/server/protocol/v0_8/FieldTable.java index 9608fc4..c1c387d 100644 --- a/broker-core/src/main/java/org/apache/qpid/server/protocol/v0_8/FieldTable.java +++ b/broker-core/src/main/java/org/apache/qpid/server/protocol/v0_8/FieldTable.java @@ -132,33 +132,39 @@ public class FieldTable { if (_encodedSize > 0) { - _properties = new LinkedHashMap<>(INITIAL_HASHMAP_CAPACITY); + _properties = decode(); + } + } - _encodedForm.mark(); - try - { - do - { - final String key = AMQShortString.readAMQShortStringAsString(_encodedForm); - AMQTypedValue value = AMQTypedValue.readFromBuffer(_encodedForm); - _properties.put(key, value); - } - while (_encodedForm.hasRemaining()); - } - finally - { - _encodedForm.reset(); - } + private Map decode() + { + final Map properties = new LinkedHashMap<>(INITIAL_HASHMAP_CAPACITY); - final long recalculateEncodedSize = calculateEncodedSize(); - if (_encodedSize != recalculateEncodedSize) + _encodedForm.mark(); + try + { + do { - throw new IllegalStateException(String.format( - "Malformed field table detected: provided encoded size '%d' does not equal calculated size '%d'", - _encodedSize, - recalculateEncodedSize)); + final String key = AMQShortString.readAMQShortStringAsString(_encodedForm); + AMQTypedValue value = AMQTypedValue.readFromBuffer(_encodedForm); + properties.put(key, value); } + while (_encodedForm.hasRemaining()); + } + finally + { + _encodedForm.reset(); + } + + final long recalculateEncodedSize = calculateEncodedSize(properties); + if (_encodedSize != recalculateEncodedSize) + { + throw new IllegalStateException(String.format( + "Malformed field table detected: provided encoded size '%d' does not equal calculated size '%d'", + _encodedSize, + recalculateEncodedSize)); } + return properties; } private AMQTypedValue setProperty(String key, AMQTypedValue val) @@ -930,17 +936,17 @@ public class FieldTable private void recalculateEncodedSize() { - int encodedSize = calculateEncodedSize(); + int encodedSize = calculateEncodedSize(_properties); _encodedSize = encodedSize; } - private int calculateEncodedSize() + private int calculateEncodedSize(final Map properties) { int encodedSize = 0; - if (_properties != null) + if (properties != null) { - for (Map.Entry e : _properties.entrySet()) + for (Map.Entry e : properties.entrySet()) { encodedSize += EncodingUtils.encodedShortStringLength(e.getKey()); encodedSize++; // the byte for the encoding Type @@ -1274,7 +1280,10 @@ public class FieldTable public synchronized void validate() { - clearEncodedForm(); + if (_properties == null && _encodedForm != null && _encodedSize > 0) + { + decode(); + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org For additional commands, e-mail: commits-help@qpid.apache.org