You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jb...@apache.org on 2021/03/22 05:03:24 UTC

[activemq] branch activemq-5.16.x updated: AMQ-6894: limit poison exception message to 1024

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

jbonofre pushed a commit to branch activemq-5.16.x
in repository https://gitbox.apache.org/repos/asf/activemq.git


The following commit(s) were added to refs/heads/activemq-5.16.x by this push:
     new 9c64c63  AMQ-6894: limit poison exception message to 1024
9c64c63 is described below

commit 9c64c63c7b2609d732a63ad6c3413c2712525e02
Author: Andrei Shakirin <an...@gmail.com>
AuthorDate: Wed Feb 7 19:28:55 2018 +0100

    AMQ-6894: limit poison exception message to 1024
    
    (cherry picked from commit d0dab2e88b44702d26dd0883c9940b97ee03fdeb)
---
 .../openwire/v1/BaseDataStreamMarshaller.java      | 13 +++++--
 .../openwire/v10/BaseDataStreamMarshaller.java     | 13 +++++--
 .../openwire/v1/BaseDataStreamMarshallerTest.java  | 40 ++++++++++++++++++++++
 .../openwire/v10/BaseDataStreamMarshallerTest.java | 40 ++++++++++++++++++++++
 4 files changed, 100 insertions(+), 6 deletions(-)

diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java
index 0b07a3b..b2c997e 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java
@@ -30,6 +30,7 @@ import org.apache.activemq.util.ByteSequence;
 public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
 
     public static final Constructor STACK_TRACE_ELEMENT_CONSTRUCTOR;
+    private static final int MAX_EXCEPTION_MESSAGE_SIZE = 1024;
 
     static {
         Constructor constructor = null;
@@ -244,7 +245,7 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
             int rc = 0;
             bs.writeBoolean(true);
             rc += tightMarshalString1(o.getClass().getName(), bs);
-            rc += tightMarshalString1(o.getMessage(), bs);
+            rc += tightMarshalString1(cutMessageIfNeeded(o.getMessage()), bs);
             if (wireFormat.isStackTraceEnabled()) {
                 rc += 2;
                 StackTraceElement[] stackTrace = o.getStackTrace();
@@ -265,7 +266,7 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
                                           BooleanStream bs) throws IOException {
         if (bs.readBoolean()) {
             tightMarshalString2(o.getClass().getName(), dataOut, bs);
-            tightMarshalString2(o.getMessage(), dataOut, bs);
+            tightMarshalString2(cutMessageIfNeeded(o.getMessage()), dataOut, bs);
             if (wireFormat.isStackTraceEnabled()) {
                 StackTraceElement[] stackTrace = o.getStackTrace();
                 dataOut.writeShort(stackTrace.length);
@@ -551,7 +552,7 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
         dataOut.writeBoolean(o != null);
         if (o != null) {
             looseMarshalString(o.getClass().getName(), dataOut);
-            looseMarshalString(o.getMessage(), dataOut);
+            looseMarshalString(cutMessageIfNeeded(o.getMessage()), dataOut);
             if (wireFormat.isStackTraceEnabled()) {
                 StackTraceElement[] stackTrace = o.getStackTrace();
                 dataOut.writeShort(stackTrace.length);
@@ -642,4 +643,10 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
         }
         return rc;
     }
+
+    protected String cutMessageIfNeeded(final String message) {
+        return (message.length() > MAX_EXCEPTION_MESSAGE_SIZE)?
+            message.substring(0, MAX_EXCEPTION_MESSAGE_SIZE - 3) + "..." : message;
+            
+    }
 }
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshaller.java
index 091743e..a570d3d 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshaller.java
@@ -29,6 +29,7 @@ import org.apache.activemq.util.ByteSequence;
 public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
 
     public static final Constructor STACK_TRACE_ELEMENT_CONSTRUCTOR;
+    private static final int MAX_EXCEPTION_MESSAGE_SIZE = 1024;
 
     static {
         Constructor constructor = null;
@@ -243,7 +244,7 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
             int rc = 0;
             bs.writeBoolean(true);
             rc += tightMarshalString1(o.getClass().getName(), bs);
-            rc += tightMarshalString1(o.getMessage(), bs);
+            rc += tightMarshalString1(cutMessageIfNeeded(o.getMessage()), bs);
             if (wireFormat.isStackTraceEnabled()) {
                 rc += 2;
                 StackTraceElement[] stackTrace = o.getStackTrace();
@@ -264,7 +265,7 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
                                           BooleanStream bs) throws IOException {
         if (bs.readBoolean()) {
             tightMarshalString2(o.getClass().getName(), dataOut, bs);
-            tightMarshalString2(o.getMessage(), dataOut, bs);
+            tightMarshalString2(cutMessageIfNeeded(o.getMessage()), dataOut, bs);
             if (wireFormat.isStackTraceEnabled()) {
                 StackTraceElement[] stackTrace = o.getStackTrace();
                 dataOut.writeShort(stackTrace.length);
@@ -550,7 +551,7 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
         dataOut.writeBoolean(o != null);
         if (o != null) {
             looseMarshalString(o.getClass().getName(), dataOut);
-            looseMarshalString(o.getMessage(), dataOut);
+            looseMarshalString(cutMessageIfNeeded(o.getMessage()), dataOut);
             if (wireFormat.isStackTraceEnabled()) {
                 StackTraceElement[] stackTrace = o.getStackTrace();
                 dataOut.writeShort(stackTrace.length);
@@ -641,4 +642,10 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
         }
         return rc;
     }
+    
+    protected String cutMessageIfNeeded(final String message) {
+        return (message.length() > MAX_EXCEPTION_MESSAGE_SIZE)?
+            message.substring(0, MAX_EXCEPTION_MESSAGE_SIZE - 3) + "..." : message;
+            
+    }
 }
diff --git a/activemq-client/src/test/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshallerTest.java b/activemq-client/src/test/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshallerTest.java
new file mode 100644
index 0000000..cc2640d
--- /dev/null
+++ b/activemq-client/src/test/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshallerTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.activemq.openwire.v1;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import javax.jms.MessageFormatException;
+
+import org.junit.Test;
+
+public class BaseDataStreamMarshallerTest {
+
+    private static final int MAX_MESSAGE_LENGTH = 1024;
+
+    @Test
+    public void cutMessageIfNeeded() throws MessageFormatException {
+        char[] message = new char[2056];
+        Arrays.fill(message, '1');
+        String cutMessage = (new WireFormatInfoMarshaller()).cutMessageIfNeeded(String.valueOf(message));
+        assertEquals("Expected length " + MAX_MESSAGE_LENGTH, MAX_MESSAGE_LENGTH, cutMessage.length());
+        assertTrue("Expected message tail ...", cutMessage.endsWith("..."));
+    }
+}
\ No newline at end of file
diff --git a/activemq-client/src/test/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshallerTest.java b/activemq-client/src/test/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshallerTest.java
new file mode 100644
index 0000000..6aebe27
--- /dev/null
+++ b/activemq-client/src/test/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshallerTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.activemq.openwire.v10;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import javax.jms.MessageFormatException;
+
+import org.junit.Test;
+
+public class BaseDataStreamMarshallerTest {
+
+    private static final int MAX_MESSAGE_LENGTH = 1024;
+
+    @Test
+    public void cutMessageIfNeeded() throws MessageFormatException {
+        char[] message = new char[2056];
+        Arrays.fill(message, '1');
+        String cutMessage = (new WireFormatInfoMarshaller()).cutMessageIfNeeded(String.valueOf(message));
+        assertEquals("Expected length " + MAX_MESSAGE_LENGTH, MAX_MESSAGE_LENGTH, cutMessage.length());
+        assertTrue("Expected message tail ...", cutMessage.endsWith("..."));
+    }
+}
\ No newline at end of file