Skip to content

Commit 80fd351

Browse files
committed
Bug 66425: Avoid exceptions found via poi-fuzz
Prevent too deep nesting by throwing an exception instead of just not parsing more nesting-levels as this still caused OOMs. Allow to adjust the limit via static setter as elsewhere to give users a chance to parse very complicated files if really necessary. https://issues.oss-fuzz.com/issues/42528505 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1923277 13f79535-47bb-0310-9956-ffa450edef68
1 parent dd647b5 commit 80fd351

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/PointerContainingStream.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
3030
public class PointerContainingStream extends Stream { // TODO - instantiable superclass
3131
private static final Logger LOG = PoiLogManager.getLogger(PointerContainingStream.class);
3232

33-
private static final int MAX_CHILDREN_NESTING = 500;
33+
private static int MAX_CHILDREN_NESTING = 500;
3434

3535
private final Pointer[] childPointers;
3636
private Stream[] childStreams;
@@ -42,7 +42,7 @@ protected PointerContainingStream(Pointer pointer, StreamStore store, ChunkFacto
4242
super(pointer, store);
4343
this.chunkFactory = chunkFactory;
4444
this.pointerFactory = pointerFactory;
45-
45+
4646
// Have the child pointers identified and created
4747
childPointers = pointerFactory.createContainerPointers(pointer, store.getContents());
4848
}
@@ -69,14 +69,15 @@ public void findChildren(byte[] documentData) {
6969

7070
private void findChildren(byte[] documentData, int nesting) {
7171
if (nesting > MAX_CHILDREN_NESTING) {
72-
LOG.warn("Encountered too deep nesting, cannot fully process stream " +
73-
" with more than " + MAX_CHILDREN_NESTING + " nested children." +
74-
" Some data could not be parsed.");
75-
return;
72+
throw new IllegalArgumentException("Encountered too deep nesting, cannot process stream " +
73+
"with more than " + MAX_CHILDREN_NESTING + " nested children. " +
74+
"Some data could not be parsed. You can call setMaxChildrenNesting() to adjust " +
75+
"this limit.");
7676
}
7777

7878
// For each pointer, generate the Stream it points to
7979
childStreams = new Stream[childPointers.length];
80+
8081
for(int i=0; i<childPointers.length; i++) {
8182
Pointer ptr = childPointers[i];
8283
childStreams[i] = Stream.createStream(ptr, documentData, chunkFactory, pointerFactory);
@@ -95,4 +96,12 @@ private void findChildren(byte[] documentData, int nesting) {
9596
}
9697
}
9798
}
99+
100+
public static int getMaxChildrenNesting() {
101+
return MAX_CHILDREN_NESTING;
102+
}
103+
104+
public static void setMaxChildrenNesting(int maxChildrenNesting) {
105+
MAX_CHILDREN_NESTING = maxChildrenNesting;
106+
}
98107
}
Binary file not shown.

test-data/spreadsheet/stress.xls

512 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)