]> source.dussan.org Git - poi.git/commitdiff
some more checks for int overflows
authorPJ Fanning <fanningpj@apache.org>
Mon, 15 Apr 2019 23:10:04 +0000 (23:10 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 15 Apr 2019 23:10:04 +0000 (23:10 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1857609 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/poifs/filesystem/POIFSDocument.java
src/java/org/apache/poi/poifs/property/RootProperty.java
src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java

index a47b2d8300358d42695f53c726865794c8781766..e43029d459b9c782239397ae936ad3c443d6854f 100644 (file)
@@ -154,7 +154,7 @@ public final class POIFSDocument implements POIFSViewable, Iterable<ByteBuffer>
            }
        }
 
-       return (int)length;
+       return Math.toIntExact(length);
    }
    
    /**
index 3cb4a6e43b963ff41f49a6be37cd153aeef6aff0..c74a02a29dc91b67e74755980338fdf9f6c769e0 100644 (file)
@@ -17,6 +17,7 @@
 
 package org.apache.poi.poifs.property;
 
+import org.apache.commons.math3.util.ArithmeticUtils;
 import org.apache.poi.poifs.common.POIFSConstants;
 
 /**
@@ -55,7 +56,7 @@ public final class RootProperty extends DirectoryProperty {
     {
         final int BLOCK_SHIFT = 6;
         final int _block_size = 1 << BLOCK_SHIFT;
-        super.setSize(size * _block_size);
+        super.setSize(ArithmeticUtils.mulAndCheck(size, _block_size));
     }
 
     /**
index a487b36ec49a5db17fd58024a72f8fc9455172ec..a4789820217edb651e2a03a59a727385f863642d 100644 (file)
@@ -455,7 +455,7 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
                         Collections.sort(allValues);
                     }
                     
-                    int limit = (int) conf.getRank();
+                    int limit = Math.toIntExact(conf.getRank());
                     if (conf.getPercent()) {
                         limit = allValues.size() * limit / 100;
                     }