package org.apache.poi.hdgf.streams;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hdgf.chunks.ChunkFactory;
import org.apache.poi.hdgf.pointers.Pointer;
import org.apache.poi.hdgf.pointers.PointerFactory;
* other data too.
*/
public class PointerContainingStream extends Stream { // TODO - instantiable superclass
- private Pointer[] childPointers;
+ private static final Logger LOG = LogManager.getLogger(PointerContainingStream.class);
+
+ private static final int MAX_CHILDREN_NESTING = 1000;
+
+ private final Pointer[] childPointers;
private Stream[] childStreams;
- private ChunkFactory chunkFactory;
- private PointerFactory pointerFactory;
+ private final ChunkFactory chunkFactory;
+ private final PointerFactory pointerFactory;
protected PointerContainingStream(Pointer pointer, StreamStore store, ChunkFactory chunkFactory, PointerFactory pointerFactory) {
super(pointer, store);
* those if appropriate.
*/
public void findChildren(byte[] documentData) {
+ findChildren(documentData, 0);
+ }
+
+ private void findChildren(byte[] documentData, int nesting) {
+ if (nesting > MAX_CHILDREN_NESTING) {
+ LOG.warn("Encountered too deep nesting, cannot fully process stream " +
+ " with more than " + MAX_CHILDREN_NESTING + " nested children." +
+ " Some data could not be parsed.");
+ return;
+ }
+
// For each pointer, generate the Stream it points to
childStreams = new Stream[childPointers.length];
for(int i=0; i<childPointers.length; i++) {
if(childStreams[i] instanceof PointerContainingStream) {
PointerContainingStream child =
(PointerContainingStream)childStreams[i];
- child.findChildren(documentData);
+ child.findChildren(documentData, nesting + 1);
}
}
}