cloud-fan commented on code in PR #56746:
URL: https://github.com/apache/spark/pull/56746#discussion_r3748446928


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala:
##########
@@ -2053,16 +2053,19 @@ case class Slice(x: Expression, start: Expression, 
length: Expression)
     val lengthInt = lengthVal.asInstanceOf[Int]
     val arr = xVal.asInstanceOf[ArrayData]
     val startIndex = ArrayExpressionUtils.sliceStartIndex(startInt, 
arr.numElements(), prettyName)
-    if (lengthInt < 0) {
-      throw 
QueryExecutionErrors.unexpectedValueForLengthInFunctionError(prettyName, 
lengthInt)
-    }
+    // Resolve (and validate) the result length via the shared helper, 
mirroring the codegen path.
+    // Besides rejecting a negative length, this clamps the length to the 
elements remaining after
+    // `startIndex`, so `startIndex + resLength` cannot overflow `Int` for a 
large length -- the

Review Comment:
   This no-overflow claim does not hold for an out-of-range `Int.MinValue` 
start: `numElements - startIndex` and the subsequent addition can still wrap. 
The result is safe because the invalid-start guard discards `resLength`, so 
please qualify this guarantee to valid start indexes or mention that guard 
explicitly.



-- 
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: [email protected]

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