gosonzhang commented on code in PR #11119:
URL: https://github.com/apache/inlong/pull/11119#discussion_r1795475139


##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/utils/ProxyUtils.java:
##########
@@ -92,6 +92,46 @@ public static boolean isBodyValid(List<byte[]> bodyList) {
         return true;
     }
 
+    /**
+     * Check if the body length exceeds the maximum limit, if the maximum 
limit is less than or equal to 0, it is not checked
+     * @param body
+     * @param maxLen
+     * @return
+     */
+    public static boolean bodyLengthCheck(byte[] body, int maxLen) {

Review Comment:
   Function names should have clear meanings, legal lengths, or illegal lengths.



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/config/ProxyConfigManager.java:
##########
@@ -632,7 +632,7 @@ private ProxyConfigEntry 
getProxyConfigEntry(DataProxyNodeResponse proxyCluster)
         if (ObjectUtils.isNotEmpty(proxyCluster.getIsSwitch())) {
             isSwitch = proxyCluster.getIsSwitch();
         }
-
+        int maxPacketLength = nodeList.get(0).getMaxPacketLength() != null ? 
nodeList.get(0).getMaxPacketLength() : 0;

Review Comment:
   It is better to use a negative number when not set. 0 is also an allowed 
length.



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/utils/ProxyUtils.java:
##########
@@ -92,6 +92,46 @@ public static boolean isBodyValid(List<byte[]> bodyList) {
         return true;
     }
 
+    /**
+     * Check if the body length exceeds the maximum limit, if the maximum 
limit is less than or equal to 0, it is not checked
+     * @param body
+     * @param maxLen
+     * @return
+     */
+    public static boolean bodyLengthCheck(byte[] body, int maxLen) {
+        // Not valid if the maximum limit is less than or equal to 0
+        if (maxLen <= 0) {
+            return true;
+        }
+        if (body.length > maxLen) {
+            logger.error("body length is too long, max length is {}", maxLen);

Review Comment:
   The failure logs for messages should be at debug level to avoid excessive 
junk logs.



##########
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/utils/ProxyUtils.java:
##########
@@ -92,6 +92,46 @@ public static boolean isBodyValid(List<byte[]> bodyList) {
         return true;
     }
 
+    /**
+     * Check if the body length exceeds the maximum limit, if the maximum 
limit is less than or equal to 0, it is not checked
+     * @param body
+     * @param maxLen
+     * @return
+     */
+    public static boolean bodyLengthCheck(byte[] body, int maxLen) {
+        // Not valid if the maximum limit is less than or equal to 0
+        if (maxLen <= 0) {
+            return true;
+        }
+        if (body.length > maxLen) {
+            logger.error("body length is too long, max length is {}", maxLen);
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Check if the total body length exceeds the maximum limit, if the 
maximum limit is less than or equal to 0, it is not checked
+     * @param bodyList
+     * @param maxLen
+     * @return
+     */
+    public static boolean bodyLengthCheck(List<byte[]> bodyList, int maxLen) {

Review Comment:
   The maximum packet length includes the length of the attribute part. If you 
only check the body part, it is best to be about 10k smaller than the length 
provided by the Manager to avoid boundary problems.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@inlong.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to