maropu commented on a change in pull request #28750:
URL: https://github.com/apache/spark/pull/28750#discussion_r438066830



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/StringUtils.scala
##########
@@ -123,7 +123,11 @@ object StringUtils extends Logging {
           val stringToAppend = if (available >= sLen) s else s.substring(0, 
available)
           strings.append(stringToAppend)
         }
-        length += sLen
+
+        // Cap the length at  ByteArrayMethods.MAX_ROUNDED_ARRAY_LENGTH. 
Otherwise, we
+        // will overflow length causing StringIndexOutOfBoundsException in the 
substring call
+        // above.

Review comment:
       The comment in the code side looks okay and how about this?
   ```
           // Keeps the total length of appended strings. Note that we need to 
cap the length at
           // `ByteArrayMethods.MAX_ROUNDED_ARRAY_LENGTH`; otherwise, we will 
overflow
           // length causing StringIndexOutOfBoundsException in the substring 
call above.
           length = Math.min(length.toLong + sLen, 
ByteArrayMethods.MAX_ROUNDED_ARRAY_LENGTH).toInt
   ```




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to