From bc11cc335efff222d4f144055a690558c00edc49 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 7 Feb 2025 21:44:50 +0000 Subject: [PATCH] [bug-69563] try to avoid int overflow in Zip64 code (probably just moves the problem somewhere else though) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1923647 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/xssf/streaming/OpcOutputStream.java | 6 +++--- .../main/java/org/apache/poi/xssf/streaming/Zip64Impl.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/OpcOutputStream.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/OpcOutputStream.java index 2079746f94..c3fc63eebb 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/OpcOutputStream.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/OpcOutputStream.java @@ -37,7 +37,7 @@ class OpcOutputStream extends DeflaterOutputStream { private final List entries = new ArrayList<>(); private final CRC32 crc = new CRC32(); private Entry current; - private int written = 0; + private long written = 0; private boolean finished = false; /** @@ -84,7 +84,7 @@ class OpcOutputStream extends DeflaterOutputStream { } current.size = def.getBytesRead(); - current.compressedSize = Math.toIntExact(def.getBytesWritten()); + current.compressedSize = def.getBytesWritten(); current.crc = crc.getValue(); written += current.compressedSize; @@ -106,7 +106,7 @@ class OpcOutputStream extends DeflaterOutputStream { if(current != null) { closeEntry(); } - int offset = written; + long offset = written; for (Entry entry : entries) { written += spec.writeCEN(entry); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/Zip64Impl.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/Zip64Impl.java index d2e00f56ed..647d94d436 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/Zip64Impl.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/Zip64Impl.java @@ -46,8 +46,8 @@ class Zip64Impl { final String filename; long crc; long size; - int compressedSize; - int offset; + long compressedSize; + long offset; Entry(String filename) { this.filename = filename; @@ -128,7 +128,7 @@ class Zip64Impl { /** * Write End of central directory record (EOCD) */ - int writeEND(int entriesCount, int offset, int length) throws IOException { + int writeEND(int entriesCount, long offset, long length) throws IOException { written = 0; writeInt(PK0506); // "PK\005\006" writeShort(0); // number of this disk