You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2019/06/18 09:16:57 UTC

[qpid-broker-j] 04/07: QPID-8316: [Broker-J] Message validation should not store decoded headers in heap

This is an automated email from the ASF dual-hosted git repository.

orudyy pushed a commit to branch 7.1.x
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git

commit f0c28c936951cf6fc345768ebcf9a50f48cfbec4
Author: Alex Rudyy <or...@apache.org>
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      | 28 +++++++++++++---------
 1 file changed, 17 insertions(+), 11 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 7ea7958..3c14ebb 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
@@ -109,14 +109,11 @@ public class FieldTable
         return value;
     }
 
-    private void decode()
+    private Map<String, AMQTypedValue> decode()
     {
+        final Map<String, AMQTypedValue> properties = new HashMap<>();
         if (_encodedSize > 0 && _encodedForm != null)
         {
-            if (!_properties.isEmpty())
-            {
-                _properties.clear();
-            }
             _encodedForm.mark();
             try
             {
@@ -126,7 +123,7 @@ public class FieldTable
 
                     checkPropertyName(key);
                     AMQTypedValue value = AMQTypedValue.readFromBuffer(_encodedForm);
-                    _properties.put(key, value);
+                    properties.put(key, value);
                 }
                 while (_encodedForm.hasRemaining());
             }
@@ -135,7 +132,7 @@ public class FieldTable
                 _encodedForm.reset();
             }
 
-            final long recalculateEncodedSize = recalculateEncodedSize();
+            final long recalculateEncodedSize = recalculateEncodedSize(properties);
             if (_encodedSize != recalculateEncodedSize)
             {
                 throw new IllegalStateException(String.format(
@@ -144,6 +141,7 @@ public class FieldTable
                         recalculateEncodedSize));
             }
         }
+        return properties;
     }
 
     private void decodeIfNecessary()
@@ -152,7 +150,12 @@ public class FieldTable
         {
             try
             {
-                decode();
+                final Map<String, AMQTypedValue> properties = decode();
+                if (!_properties.isEmpty())
+                {
+                    _properties.clear();
+                }
+                _properties.putAll(properties);
             }
             finally
             {
@@ -344,10 +347,10 @@ public class FieldTable
         return _encodedSize;
     }
 
-    private synchronized long recalculateEncodedSize()
+    private synchronized long recalculateEncodedSize(final Map<String, AMQTypedValue> properties)
     {
         long size = 0L;
-        for (Map.Entry<String, AMQTypedValue> e : _properties.entrySet())
+        for (Map.Entry<String, AMQTypedValue> e : properties.entrySet())
         {
             String key = e.getKey();
             AMQTypedValue value = e.getValue();
@@ -533,6 +536,9 @@ public class FieldTable
 
     public synchronized void validate()
     {
-        decodeIfNecessary();
+        if (!_decoded)
+        {
+            decode();
+        }
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org