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

pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git


The following commit(s) were added to refs/heads/trunk by this push:
     new ab28e7eaec Harden integer conversions and arithmetic in HwmfBitmapDib, 
AggregateFunction, and DStarRunner (#1106)
ab28e7eaec is described below

commit ab28e7eaec4e3557203bf3a0b57db9fd9ff84bc2
Author: sahvx655-wq <[email protected]>
AuthorDate: Thu Jun 4 01:10:10 2026 +0530

    Harden integer conversions and arithmetic in HwmfBitmapDib, 
AggregateFunction, and DStarRunner (#1106)
    
    Harden integer conversions and arithmetic
    
    Co-authored-by: “sahvx655-wq” <“[email protected]”>
---
 .../src/main/java/org/apache/poi/hwmf/record/HwmfBitmapDib.java         | 2 +-
 .../java/org/apache/poi/ss/formula/functions/AggregateFunction.java     | 2 +-
 poi/src/main/java/org/apache/poi/ss/formula/functions/DStarRunner.java  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git 
a/poi-scratchpad/src/main/java/org/apache/poi/hwmf/record/HwmfBitmapDib.java 
b/poi-scratchpad/src/main/java/org/apache/poi/hwmf/record/HwmfBitmapDib.java
index 4a82faf123..e06aaeaf2d 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hwmf/record/HwmfBitmapDib.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hwmf/record/HwmfBitmapDib.java
@@ -458,7 +458,7 @@ public class HwmfBitmapDib implements GenericRecord {
         }
 
         // sometimes there are missing bytes after the imageData which will be 
0-filled
-        int imageSize = (int)Math.max(imageData.length, 
introSize+headerImageSize);
+        int imageSize = Math.toIntExact(Math.max(imageData.length, introSize + 
headerImageSize));
 
         // create the image data and leave the parsing to the ImageIO api
         byte[] buf = IOUtils.safelyAllocate(BMP_HEADER_SIZE + (long)imageSize, 
HwmfPicture.getMaxRecordLength());
diff --git 
a/poi/src/main/java/org/apache/poi/ss/formula/functions/AggregateFunction.java 
b/poi/src/main/java/org/apache/poi/ss/formula/functions/AggregateFunction.java
index 6404358ca5..78c190dbb7 100644
--- 
a/poi/src/main/java/org/apache/poi/ss/formula/functions/AggregateFunction.java
+++ 
b/poi/src/main/java/org/apache/poi/ss/formula/functions/AggregateFunction.java
@@ -49,7 +49,7 @@ public abstract class AggregateFunction extends 
MultiOperandNumericFunction {
                 return ErrorEval.NUM_ERROR;
             }
             // all other values are rounded up to the next integer
-            int k = (int) Math.ceil(dn);
+            int k = MathUtil.safeDoubleToInt(Math.ceil(dn));
 
             double result;
             try {
diff --git 
a/poi/src/main/java/org/apache/poi/ss/formula/functions/DStarRunner.java 
b/poi/src/main/java/org/apache/poi/ss/formula/functions/DStarRunner.java
index 16b0b2c259..70e1aa3927 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/functions/DStarRunner.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/DStarRunner.java
@@ -123,7 +123,7 @@ public final class DStarRunner implements Function3Arg {
             filterColumn = OperandResolver.getSingleValue(filterColumn, 
srcRowIndex, srcColumnIndex);
             if (filterColumn instanceof NumericValueEval) {
                 //fc is zero based while Excel uses 1 based column numbering
-                fc = (int) 
Math.round(((NumericValueEval)filterColumn).getNumberValue()) - 1;
+                fc = 
Math.toIntExact(Math.round(((NumericValueEval)filterColumn).getNumberValue())) 
- 1;
             } else {
                 fc = getColumnForName(filterColumn, db);
             }


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

Reply via email to