metsw24-max commented on code in PR #1064:
URL: https://github.com/apache/poi/pull/1064#discussion_r3225442783


##########
poi/src/main/java/org/apache/poi/hpsf/Array.java:
##########
@@ -71,7 +71,12 @@ void read( LittleEndianByteArrayInputStream lei ) {
         long getNumberOfScalarValues() {
             long result = 1;
             for ( ArrayDimension dimension : _dimensions ) {
-                result *= dimension._size;
+                try {
+                    result = Math.multiplyExact(result, dimension._size);
+                } catch (ArithmeticException e) {
+                    throw new IllegalPropertySetDataException(

Review Comment:
   I have dropped the try/catch wrappers in both UnicodeString.read and 
`Array.ArrayHeader.getNumberOfScalarValues` and now let `Math.multiplyExact` 
native `ArithmeticException` propagate as per your suggestion. 
   
   The redundant negative-length pre-check in `UnicodeString` is gone too 
   
   `IOUtils.safelyAllocate` already rejects negative sizes downstream so there 
is no behavior gap.
   
    Tests updated to expect `ArithmeticException`



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