qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oru...@apache.org
Subject [qpid-broker-j] 02/04: QPID-8316: [Broker-J] Message validation should not store decoded headers in heap
Date Tue, 18 Jun 2019 11:14:19 GMT
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 <orudyy@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      | 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<String, AMQTypedValue> decode()
+    {
+        final Map<String, AMQTypedValue> 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<String, AMQTypedValue> properties)
     {
         int encodedSize = 0;
-        if (_properties != null)
+        if (properties != null)
         {
-            for (Map.Entry<String, AMQTypedValue> e : _properties.entrySet())
+            for (Map.Entry<String, AMQTypedValue> 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


Mime
View raw message