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

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


The following commit(s) were added to refs/heads/master by this push:
     new a8d966a23 fix(topic): bound the topic and group text the registration 
columns cannot store (#6087)
a8d966a23 is described below

commit a8d966a23bc955145bc12a016e26f51674bf2a9f
Author: Apulupie <[email protected]>
AuthorDate: Fri Nov 27 12:54:54 2026 +0800

    fix(topic): bound the topic and group text the registration columns cannot 
store (#6087)
---
 .../studio/instance/topic/MetadataService.java     | 24 +++++++++++++
 .../studio/instance/topic/MetadataServiceTest.java | 41 ++++++++++++++++++++++
 2 files changed, 65 insertions(+)

diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/instance/topic/MetadataService.java
 
b/server/src/main/java/org/apache/rocketmq/studio/instance/topic/MetadataService.java
index 38d6e2d5e..be1d3f9d7 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/instance/topic/MetadataService.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/instance/topic/MetadataService.java
@@ -47,6 +47,7 @@ import org.apache.rocketmq.studio.common.util.CsvUtil;
 import org.apache.rocketmq.studio.common.util.MessagePropertyDisplay;
 import org.apache.rocketmq.studio.common.util.Pagination;
 import org.apache.rocketmq.studio.common.util.SystemTopicFilter;
+import org.apache.rocketmq.studio.common.util.TextBounds;
 import org.apache.rocketmq.studio.instance.group.CreateConsumerGroupDTO;
 import org.apache.rocketmq.studio.instance.group.ImportConsumerGroupsResultVO;
 import org.springframework.util.StringUtils;
@@ -85,6 +86,14 @@ public class MetadataService {
 
     private static final int MAX_PAGE_SIZE = 100;
 
+    /**
+     * Widths of the registration columns the topic and group write paths 
store their text in:
+     * {@code rmq_instance_topic.name}, {@code rmq_instance_topic.remark} and
+     * {@code rmq_instance_group.name} are all {@code VARCHAR(255)}.
+     */
+    static final int MAX_REGISTRATION_NAME_CODE_POINTS = 255;
+    static final int MAX_TOPIC_REMARK_CODE_POINTS = 255;
+
     private final MetadataProvider metadataProvider;
     private final AdminClient adminClient;
     private final InstanceProviderRegistry providerRegistry;
@@ -704,6 +713,7 @@ public class MetadataService {
             throw new BusinessException(400, "Group request is required");
         }
         group.setName(requireName(group.getName(), "groupName"));
+        requireRegistrationText(group.getName(), 
MAX_REGISTRATION_NAME_CODE_POINTS, "groupName");
         String target = requireWriteInstance(instanceId, new 
Resource(Kind.GROUP, group.getName()),
                 Operation.UPDATE_GROUP.equals(operation));
         group.setInstanceId(target);
@@ -835,6 +845,8 @@ public class MetadataService {
             throw new BusinessException(400, "Topic request is required");
         }
         topic.setName(requireName(topic.getName(), "topicName"));
+        requireRegistrationText(topic.getName(), 
MAX_REGISTRATION_NAME_CODE_POINTS, "topicName");
+        requireRegistrationText(topic.getRemark(), 
MAX_TOPIC_REMARK_CODE_POINTS, "remark");
     }
 
     private String requireWriteInstance(String instanceId, Resource resource, 
boolean required) {
@@ -1050,6 +1062,18 @@ public class MetadataService {
         return value.trim();
     }
 
+    /**
+     * Bounds a value to the width of the registration column that stores it. 
Letting a longer value
+     * through does not store it: MySQL rejects the write, so the caller would 
receive a 500 from the
+     * persistence layer instead of the validation error the surrounding paths 
already return.
+     * Counted in code points, the unit MySQL counts a {@code varchar} in.
+     */
+    private static void requireRegistrationText(String value, int 
maxCodePoints, String fieldName) {
+        if (TextBounds.codePointCount(value) > maxCodePoints) {
+            throw new BusinessException(400, fieldName + " must not exceed " + 
maxCodePoints + " characters");
+        }
+    }
+
     private String topicDetail(TopicVO topic) {
         return "type=" + optionalDetail(topic.getType())
                 + ", writeQueues=" + topic.getWriteQueues()
diff --git 
a/server/src/test/java/org/apache/rocketmq/studio/instance/topic/MetadataServiceTest.java
 
b/server/src/test/java/org/apache/rocketmq/studio/instance/topic/MetadataServiceTest.java
index fad5031aa..c8c50aa40 100644
--- 
a/server/src/test/java/org/apache/rocketmq/studio/instance/topic/MetadataServiceTest.java
+++ 
b/server/src/test/java/org/apache/rocketmq/studio/instance/topic/MetadataServiceTest.java
@@ -622,6 +622,47 @@ class MetadataServiceTest {
         verifyNoInteractions(operationAuditService);
     }
 
+    @Test
+    void createTopicShouldRejectARemarkTheRegistrationColumnCannotStoreTest() {
+        TopicVO input = new TopicVO();
+        input.setName("orders");
+        input.setWriteQueues(8);
+        input.setReadQueues(8);
+        input.setRemark("r".repeat(256));
+
+        assertThatThrownBy(() -> metadataService.createTopic("instance-a", 
input))
+                .isInstanceOf(BusinessException.class)
+                .hasMessageContaining("must not exceed 255 characters");
+
+        verifyNoInteractions(apacheProvider);
+    }
+
+    @Test
+    void createTopicShouldAcceptARemarkAtTheRegistrationColumnWidthTest() {
+        TopicVO input = new TopicVO();
+        input.setName("orders");
+        input.setWriteQueues(8);
+        input.setReadQueues(8);
+        input.setRemark("r".repeat(255));
+        when(apacheProvider.createTopic(eq("instance-a"), 
any(TopicVO.class))).thenReturn(input);
+
+        assertThat(metadataService.createTopic("instance-a", 
input).getRemark()).hasSize(255);
+        verify(apacheProvider).createTopic("instance-a", input);
+    }
+
+    @Test
+    void 
createConsumerGroupShouldRejectANameTheRegistrationColumnCannotStoreTest() {
+        ConsumerGroupVO group = new ConsumerGroupVO();
+        group.setName("g".repeat(256));
+        group.setInstanceId("instance-a");
+
+        assertThatThrownBy(() -> metadataService.createConsumerGroup(group))
+                .isInstanceOf(BusinessException.class)
+                .hasMessageContaining("must not exceed 255 characters");
+
+        verifyNoInteractions(apacheProvider);
+    }
+
     @ParameterizedTest
     @ValueSource(booleans = {false, true})
     void createTopicShouldRejectSystemTopicNamesTest(boolean explicitInstance) 
{

Reply via email to