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

lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/rocketmq-studio by this push:
     new 0315ee621 fix(dlq): truncate the Body Base64 Excel column so oversized 
binary exports do not fail (#6337)
0315ee621 is described below

commit 0315ee62143b0c042fe2b76ffca0f4adf8021ab1
Author: cyberslack_lee <[email protected]>
AuthorDate: Thu Oct 15 18:08:53 2026 +0800

    fix(dlq): truncate the Body Base64 Excel column so oversized binary exports 
do not fail (#6337)
    
    Signed-off-by: enkilee <[email protected]>
---
 .../studio/instance/dlq/DLQMessageExcelRow.java    | 19 ++++++++------
 .../instance/dlq/DLQMessageExcelRowTest.java       | 29 ++++++++++++++++++++++
 2 files changed, 41 insertions(+), 7 deletions(-)

diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/instance/dlq/DLQMessageExcelRow.java
 
b/server/src/main/java/org/apache/rocketmq/studio/instance/dlq/DLQMessageExcelRow.java
index c640c5d29..5bf2626d5 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/instance/dlq/DLQMessageExcelRow.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/instance/dlq/DLQMessageExcelRow.java
@@ -70,20 +70,25 @@ public class DLQMessageExcelRow {
                 Instant.ofEpochMilli(vo.getStoreTime()), 
ZoneId.systemDefault()).format(STORE_TIME_FORMAT));
         row.setReconsumeTimes(vo.getReconsumeTimes());
         row.setKeys(vo.getKeys());
-        row.setBody(abbreviateBody(vo.getBody()));
-        row.setBodyBase64(vo.getBody() == null ? vo.getBodyBase64() : null);
+        row.setBody(abbreviateForExcelCell(vo.getBody()));
+        row.setBodyBase64(abbreviateForExcelCell(vo.getBody() == null ? 
vo.getBodyBase64() : null));
         return row;
     }
 
-    private static String abbreviateBody(String body) {
-        if (body == null || body.length() <= MAX_EXCEL_CELL_CHARS) {
-            return body;
+    /**
+     * Caps any cell-bound text at {@link #MAX_EXCEL_CELL_CHARS} so POI never 
rejects the row. The
+     * cut lands on a code-point boundary so a surrogate pair is never split; 
for Base64 (pure ASCII)
+     * the guard never fires and the method is just a length cap.
+     */
+    private static String abbreviateForExcelCell(String text) {
+        if (text == null || text.length() <= MAX_EXCEL_CELL_CHARS) {
+            return text;
         }
         int keep = MAX_EXCEL_CELL_CHARS - TRUNCATION_SUFFIX.length();
         // Back off onto a code-point boundary so the cut never splits a 
surrogate pair.
-        if (Character.isHighSurrogate(body.charAt(keep - 1))) {
+        if (Character.isHighSurrogate(text.charAt(keep - 1))) {
             keep--;
         }
-        return body.substring(0, keep) + TRUNCATION_SUFFIX;
+        return text.substring(0, keep) + TRUNCATION_SUFFIX;
     }
 }
diff --git 
a/server/src/test/java/org/apache/rocketmq/studio/instance/dlq/DLQMessageExcelRowTest.java
 
b/server/src/test/java/org/apache/rocketmq/studio/instance/dlq/DLQMessageExcelRowTest.java
index 0747a6566..c6fe1e0fc 100644
--- 
a/server/src/test/java/org/apache/rocketmq/studio/instance/dlq/DLQMessageExcelRowTest.java
+++ 
b/server/src/test/java/org/apache/rocketmq/studio/instance/dlq/DLQMessageExcelRowTest.java
@@ -80,6 +80,35 @@ class DLQMessageExcelRowTest {
         assertThat(cell.codePoints()).noneMatch(codePoint -> codePoint >= 
0xD800 && codePoint <= 0xDFFF);
     }
 
+    @Test
+    void shouldClampAnOversizedBodyBase64Test() {
+        // A binary message carries its raw bytes as Base64 in the Body Base64 
column. Base64 is pure
+        // ASCII so there is no surrogate pair to worry about, but a body over 
~24 KB still encodes to
+        // more than POI's 32767-char cell limit and would abort the whole 
export with a 502.
+        DLQMessageVO message = DLQMessageVO.builder()
+                .msgId("binary-huge")
+                .storeTime(1_700_000_000_000L)
+                .bodyBase64("A".repeat(40_000))
+                .build();
+
+        String cell = DLQMessageExcelRow.from(message).getBodyBase64();
+
+        assertThat(cell).hasSize(32_767).endsWith("...[truncated]");
+    }
+
+    @Test
+    void shouldLeaveAShortBodyBase64UntouchedTest() {
+        DLQMessageVO message = DLQMessageVO.builder()
+                .msgId("binary-small")
+                .storeTime(1_700_000_000_000L)
+                .bodyBase64("wyg=")
+                .build();
+
+        String cell = DLQMessageExcelRow.from(message).getBodyBase64();
+
+        assertThat(cell).isEqualTo("wyg=");
+    }
+
     private static Map<String, String> 
firstDataRowByColumnName(List<DLQMessageVO> messages) {
         List<Map<Integer, String>> rows = readBack(messages);
         Map<Integer, String> header = rows.get(0);

Reply via email to