Bug 66425: Add memory-safeguard in one more place

We try to generally avoid overly large allocations in places
where arrays are allocated. 

We add one more such check for pictures in HSLF.

We might need to increase the used value of 10MB if users report 
larger files being used frequently. 

Overriding this check via IOUtils is possible.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1911525 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2023-08-07 20:35:59 +00:00
parent 163ff25594
commit 1b7613329e
5 changed files with 35 additions and 9 deletions

View File

@ -94,6 +94,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
private static final int DEFAULT_MAX_RECORD_LENGTH = 200_000_000;
private static final int MAX_DOCUMENT_SIZE = 100_000_000;
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
private static final int MAX_IMAGE_LENGTH = 10_000_000;
// Holds metadata on where things are in our document
private CurrentUserAtom currentUser;
@ -407,7 +408,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
EscherContainerRecord blipStore = getBlipStore();
byte[] pictstream;
try (DocumentInputStream is = getDirectory().createDocumentInputStream(entry)) {
pictstream = IOUtils.toByteArray(is, entry.getSize());
pictstream = IOUtils.toByteArray(is, entry.getSize(), MAX_IMAGE_LENGTH);
}
List<PictureFactory> factories = new ArrayList<>();

View File

@ -16,17 +16,23 @@
==================================================================== */
package org.apache.poi.hslf.dev;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.File;
import java.util.Collections;
import java.util.Set;
import org.apache.poi.EmptyFileException;
import org.apache.poi.hslf.HSLFTestDataSamples;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestPPTXMLDump extends BaseTestPPTIterating {
static final Set<String> LOCAL_EXCLUDED = new HashSet<>();
static {
LOCAL_EXCLUDED.add("clusterfuzz-testcase-minimized-POIHSLFFuzzer-5306877435838464.ppt");
}
@Test
void testMain() throws Exception {
PPTXMLDump.main(new String[0]);
@ -41,7 +47,13 @@ public class TestPPTXMLDump extends BaseTestPPTIterating {
@Override
void runOneFile(File pFile) throws Exception {
PPTXMLDump.main(new String[]{pFile.getAbsolutePath()});
try {
PPTXMLDump.main(new String[]{pFile.getAbsolutePath()});
} catch (IndexOutOfBoundsException e) {
if (!LOCAL_EXCLUDED.contains(pFile.getName())) {
throw e;
}
}
}
@Override

View File

@ -20,12 +20,19 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.apache.poi.EmptyFileException;
import org.apache.poi.hslf.HSLFTestDataSamples;
import org.junit.jupiter.api.Test;
public class TestSlideIdListing extends BaseTestPPTIterating {
static final Set<String> LOCAL_EXCLUDED = new HashSet<>();
static {
LOCAL_EXCLUDED.add("clusterfuzz-testcase-minimized-POIHSLFFuzzer-5306877435838464.ppt");
}
@Test
void testMain() throws IOException {
// calls System.exit(): SlideIdListing.main(new String[0]);
@ -37,6 +44,12 @@ public class TestSlideIdListing extends BaseTestPPTIterating {
@Override
void runOneFile(File pFile) throws Exception {
SlideIdListing.main(new String[]{pFile.getAbsolutePath()});
try {
SlideIdListing.main(new String[]{pFile.getAbsolutePath()});
} catch (IllegalArgumentException e) {
if (!LOCAL_EXCLUDED.contains(pFile.getName())) {
throw e;
}
}
}
}

Binary file not shown.