You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2026/08/16 07:05:47 UTC
(poi) 02/04: Add allocation-check and add reproducer for OOM
This is an automated email from the ASF dual-hosted git repository.
centic9 pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
commit 2ae61fa41c3d95280dabb11f07a5a093ea2c08db
Author: Dominik Stadler <ce...@apache.org>
AuthorDate: Fri Aug 7 08:17:06 2026 +0200
Add allocation-check and add reproducer for OOM
---
.../poi/xssf/usermodel/XSSFPivotCacheRecords.java | 20 +++++++++++++-------
test-data/poi-integration-exceptions.csv | 4 +++-
test-data/spreadsheet/LIBRE_OFFICE-116306-0.xlsx | Bin 0 -> 2859963 bytes
3 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheRecords.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheRecords.java
index 3d0472656b..2545e274b0 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheRecords.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheRecords.java
@@ -27,14 +27,16 @@ import javax.xml.namespace.QName;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.util.Beta;
+import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.SuppressForbidden;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCacheRecords;
public class XSSFPivotCacheRecords extends POIXMLDocumentPart {
private CTPivotCacheRecords ctPivotCacheRecords;
-
+
@Beta
public XSSFPivotCacheRecords() {
super();
@@ -46,7 +48,7 @@ public class XSSFPivotCacheRecords extends POIXMLDocumentPart {
* Should only be called when reading in an existing file.
*
* @param part - The package part that holds xml data representing this pivot cache records.
- *
+ *
* @since 3.14-Beta1
*/
@Beta
@@ -56,13 +58,17 @@ public class XSSFPivotCacheRecords extends POIXMLDocumentPart {
readFrom(stream);
}
}
-
+
+ @SuppressForbidden(value = "InputStream.available() is used on purpose here to have at least some sort of safety-catch on large allocations")
@Beta
protected void readFrom(InputStream is) throws IOException {
- try {
- XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS);
- //Removing root element
- options.setLoadReplaceDocumentElement(null);
+ try {
+ XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS);
+ //Removing root element
+ options.setLoadReplaceDocumentElement(null);
+
+ IOUtils.safelyAllocateCheck(is.available(), 1024*1024);
+
ctPivotCacheRecords = CTPivotCacheRecords.Factory.parse(is, options);
} catch (XmlException e) {
throw new IOException(e.getLocalizedMessage());
diff --git a/test-data/poi-integration-exceptions.csv b/test-data/poi-integration-exceptions.csv
index ca54ad9323..9d002322b7 100644
--- a/test-data/poi-integration-exceptions.csv
+++ b/test-data/poi-integration-exceptions.csv
@@ -406,4 +406,6 @@ slideshow/clusterfuzz-testcase-minimized-POIFileHandlerFuzzer-6466833057382400.e
slideshow/clusterfuzz-testcase-minimized-POIHSLFFuzzer-4983252485210112.ppt,"handle,additional",HPSF,,java.lang.IndexOutOfBoundsException,Block 21 not found,
slideshow/clusterfuzz-testcase-minimized-POIHSLFFuzzer-4983252485210112.ppt,handle,HSLF,,org.apache.poi.util.RecordFormatException,Tried to allocate an array,
slideshow/clusterfuzz-testcase-minimized-POIFileHandlerFuzzer-6060921738035200.wmf,handle,HWMF,,java.lang.IllegalStateException,invalid wmf file
-spreadsheet/LIBRE_OFFICE-128382-0.xlsx,handle,XSSF,,org.apache.poi.ss.formula.FormulaParseException,Illegal table name
\ No newline at end of file
+spreadsheet/LIBRE_OFFICE-128382-0.xlsx,handle,XSSF,,org.apache.poi.ss.formula.FormulaParseException,Illegal table name
+spreadsheet/LIBRE_OFFICE-116306-0.xlsx,extract,"XSSF,OPC",,org.apache.poi.util.RecordFormatException,Tried to allocate an array
+spreadsheet/LIBRE_OFFICE-116306-0.xlsx,handle,XSSF,,org.apache.poi.util.RecordFormatException,Tried to allocate an array
diff --git a/test-data/spreadsheet/LIBRE_OFFICE-116306-0.xlsx b/test-data/spreadsheet/LIBRE_OFFICE-116306-0.xlsx
new file mode 100755
index 0000000000..9903cfd164
Binary files /dev/null and b/test-data/spreadsheet/LIBRE_OFFICE-116306-0.xlsx differ
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org