]> source.dussan.org Git - poi.git/commitdiff
use ArithmeticUtils for calculations that might overflow
authorPJ Fanning <fanningpj@apache.org>
Mon, 15 Apr 2019 15:45:59 +0000 (15:45 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 15 Apr 2019 15:45:59 +0000 (15:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1857594 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java
src/java/org/apache/poi/poifs/filesystem/TempFilePOIFSFileSystem.java

index 178f6568eef757d34995c2e99681a9c3847687a2..65c95ffee058a1f4826afe1f8ca9d6c8ad48fe9a 100644 (file)
@@ -36,6 +36,7 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.commons.math3.util.ArithmeticUtils;
 import org.apache.poi.EmptyFileException;
 import org.apache.poi.poifs.common.POIFSBigBlockSize;
 import org.apache.poi.poifs.common.POIFSConstants;
@@ -407,7 +408,8 @@ public class POIFSFileSystem extends BlockStore
         newBAT.setOurBlockIndex(offset);
         // Ensure there's a spot in the file for it
         ByteBuffer buffer = ByteBuffer.allocate(bigBlockSize.getBigBlockSize());
-        int writeTo = (1 + offset) * bigBlockSize.getBigBlockSize(); // Header isn't in BATs
+        // Header isn't in BATs
+        long writeTo = ArithmeticUtils.mulAndCheck((1 + (long)offset), (long)bigBlockSize.getBigBlockSize());
         _data.write(buffer, writeTo);
         // All done
         return newBAT;
index c16ff035a000cb95caf9c9b559ebc5789a161198..be162b607912efac9751dd30df96cef0811f7e2a 100644 (file)
@@ -42,7 +42,7 @@ public class TempFilePOIFSFileSystem extends POIFSFileSystem {
     }
 
     public void close() throws IOException {
-        if (tempFile != null) tempFile.delete();
+        if (tempFile != null && tempFile.exists()) tempFile.delete();
         super.close();
     }