EXCLUDED.put("clusterfuzz-testcase-minimized-POIHSLFFuzzer-4624961081573376.ppt", FileNotFoundException.class);
EXCLUDED.put("clusterfuzz-testcase-minimized-POIHSLFFuzzer-5018229722382336.ppt", RuntimeException.class);
EXCLUDED.put("clusterfuzz-testcase-minimized-POIHSLFFuzzer-6192650357112832.ppt", RuntimeException.class);
+ EXCLUDED.put("clusterfuzz-testcase-minimized-POIHSLFFuzzer-6614960949821440.ppt", RuntimeException.class);
}
public static Stream<Arguments> files() {
LOCAL_EXCLUDED.add("clusterfuzz-testcase-minimized-POIHSLFFuzzer-6032591399288832.ppt");
LOCAL_EXCLUDED.add("clusterfuzz-testcase-minimized-POIHSLFFuzzer-6360479850954752.ppt");
LOCAL_EXCLUDED.add("ppt_with_png_encrypted.ppt");
+ LOCAL_EXCLUDED.add("clusterfuzz-testcase-minimized-POIHSLFFuzzer-6614960949821440.ppt");
}
@Test
FAILING.add("clusterfuzz-testcase-minimized-POIHSLFFuzzer-6360479850954752.ppt");
}
+ static final Set<String> LOCAL_EXCLUDED = new HashSet<>();
+ static {
+ LOCAL_EXCLUDED.add("clusterfuzz-testcase-minimized-POIHSLFFuzzer-6614960949821440.ppt");
+ }
+
@Test
void testMain() throws IOException {
// SlideShowDumper calls IOUtils.toByteArray(is), which would fail if a different size is defined
throw e;
}
}
+
+ // these fail everywhere else, so also should fail here
+ if (LOCAL_EXCLUDED.contains(pFile.getName())) {
+ throw new RuntimeException();
+ }
}
@Override
if (childRecords == _childRecords) {
throw new IllegalStateException("Child records private data member has escaped");
}
+
+ if (childRecords.size() > MAX_NUMBER_OF_CHILDREN) {
+ throw new IllegalStateException("Cannot add more than " + MAX_NUMBER_OF_CHILDREN +
+ " child records, you can use 'EscherRecord.setMaxNumberOfChildren()' to increase the allow size");
+ }
+
_childRecords.clear();
_childRecords.addAll(childRecords);
}
* @param record the record to be added
*/
public void addChildRecord(EscherRecord record) {
+ if (_childRecords.size() >= MAX_NUMBER_OF_CHILDREN) {
+ throw new IllegalStateException("Cannot add more than " + MAX_NUMBER_OF_CHILDREN +
+ " child records, you can use 'EscherRecord.setMaxNumberOfChildren()' to increase the allow size");
+ }
+
_childRecords.add(record);
}
private short _options;
private short _recordId;
+ // arbitrarily selected; may need to increase
+ private static final int DEFAULT_MAX_NUMBER_OF_CHILDREN = 100_000;
+ protected static int MAX_NUMBER_OF_CHILDREN = DEFAULT_MAX_NUMBER_OF_CHILDREN;
+
/**
* Create a new instance
*/
@Override
public abstract EscherRecord copy();
+
+ /**
+ * @param length the max record length allowed for EscherArrayProperty
+ */
+ public static void setMaxNumberOfChildren(int length) {
+ MAX_NUMBER_OF_CHILDREN = length;
+ }
+
+ /**
+ * @return the max record length allowed for EscherArrayProperty
+ */
+ public static int getMaxNumberOfChildren() {
+ return MAX_NUMBER_OF_CHILDREN;
+ }
}
\ No newline at end of file
if (childRecords == _childRecords) {
return;
}
+
+ if (childRecords.size() > MAX_NUMBER_OF_CHILDREN) {
+ throw new IllegalStateException("Cannot add more than " + MAX_NUMBER_OF_CHILDREN +
+ " child records, you can use 'EscherRecord.setMaxNumberOfChildren()' to increase the allow size");
+ }
+
_childRecords.clear();
_childRecords.addAll(childRecords);
}
}
public void addChildRecord(EscherRecord childRecord) {
+ if (_childRecords.size() >= MAX_NUMBER_OF_CHILDREN) {
+ throw new IllegalStateException("Cannot add more than " + MAX_NUMBER_OF_CHILDREN +
+ " child records, you can use 'EscherRecord.setMaxNumberOfChildren()' to increase the allow size");
+ }
+
getChildRecords().add( childRecord );
}
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotSame;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import java.util.Arrays;
import java.util.List;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.Isolated;
/**
* Tests for {@link EscherContainerRecord}
*/
+@Isolated // this test changes global static MAX_NUMBER_OF_CHILDREN
final class TestEscherContainerRecord {
private static final POIDataSamples _samples = POIDataSamples.getDDFInstance();
byte[] data = HexRead.readFromString("0F 02 11 F1 00 00 00 00");
EscherRecord r = f.createRecord(data, 0);
r.fillFields(data, 0, f);
- assertTrue(r instanceof EscherContainerRecord);
+ assertInstanceOf(EscherContainerRecord.class, r);
assertEquals((short) 0x020F, r.getOptions());
assertEquals((short) 0xF111, r.getRecordId());
"\t, \"recordSize\": 8\n" +
"\t, \"isContainer\": true\n" +
"}";
- expected = expected.replace("\n", System.getProperty("line.separator"));
+ expected = expected.replace("\n", System.lineSeparator());
assertEquals(expected, r.toString());
EscherOptRecord r2 = new EscherOptRecord();
"\t\t}\n" +
"\t]\n" +
"}";
- expected = expected.replace("\n", System.getProperty("line.separator"));
+ expected = expected.replace("\n", System.lineSeparator());
assertEquals(expected, r.toString());
r.addChildRecord(r2);
"\t\t}\n" +
"\t]\n" +
"}";
- expected = expected.replace("\n", System.getProperty("line.separator"));
+ expected = expected.replace("\n", System.lineSeparator());
assertEquals(expected, r.toString());
}
@Override
public String getRecordName() { return ""; }
@Override
- public Enum getGenericRecordType() { return EscherRecordTypes.UNKNOWN; }
+ public Enum<?> getGenericRecordType() { return EscherRecordTypes.UNKNOWN; }
@Override
public DummyEscherRecord copy() { return null; }
}
assertEquals(chC, children2.get(0));
assertEquals(chA, children2.get(1));
}
+
+ @Test
+ void testTooManyChildren() {
+ EscherContainerRecord ecr = new EscherContainerRecord();
+
+ int before = EscherRecord.getMaxNumberOfChildren();
+ try {
+ EscherRecord.setMaxNumberOfChildren(2);
+
+ ecr.addChildRecord(new EscherDgRecord());
+ ecr.addChildRecord(new EscherDgRecord());
+ assertThrows(IllegalStateException.class,
+ () -> ecr.addChildRecord(new EscherDgRecord()));
+
+ ecr.setChildRecords(Arrays.asList(new EscherDgRecord(), new EscherDgRecord()));
+ assertThrows(IllegalStateException.class,
+ () -> ecr.setChildRecords(Arrays.asList(new EscherDgRecord(), new EscherDgRecord(), new EscherDgRecord())));
+ } finally {
+ EscherRecord.setMaxNumberOfChildren(before);
+ }
+ }
}
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.Isolated;
+import java.util.Arrays;
+
+@Isolated // this test changes global static MAX_NUMBER_OF_CHILDREN
final class TestUnknownEscherRecord {
@Test
void testFillFields() {
"\t, \"recordSize\": 8\n" +
"\t, \"data\": \"\"\n" +
"}";
- expected = expected.replace("\n", System.getProperty("line.separator"));
+ expected = expected.replace("\n", System.lineSeparator());
assertEquals(expected, r.toString() );
}
+
+ @Test
+ void testTooManyChildren() {
+ UnknownEscherRecord ecr = new UnknownEscherRecord();
+
+ int before = EscherRecord.getMaxNumberOfChildren();
+ try {
+ EscherRecord.setMaxNumberOfChildren(2);
+
+ ecr.addChildRecord(new EscherDgRecord());
+ ecr.addChildRecord(new EscherDgRecord());
+ assertThrows(IllegalStateException.class,
+ () -> ecr.addChildRecord(new EscherDgRecord()));
+
+ ecr.setChildRecords(Arrays.asList(new EscherDgRecord(), new EscherDgRecord()));
+ assertThrows(IllegalStateException.class,
+ () -> ecr.setChildRecords(Arrays.asList(new EscherDgRecord(), new EscherDgRecord(), new EscherDgRecord())));
+ } finally {
+ EscherRecord.setMaxNumberOfChildren(before);
+ }
+ }
}