"spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-4977868385681408.xls",
"spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-4651309315719168.xls",
"document/clusterfuzz-testcase-POIHWPFFuzzer-5696094627495936.doc",
+ "spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-4657005060816896.xls"
});
private static final Set<String> EXPECTED_FAILURES = StressTestUtils.unmodifiableHashSet(
import javax.swing.JLabel;
-import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.usermodel.Cell;
Matcher m = ONE_PART.matcher(format);
List<CellFormatPart> parts = new ArrayList<>();
- while (m.find()) {
- try {
- String valueDesc = m.group();
+ try {
+ while (m.find()) {
+ try {
+ String valueDesc = m.group();
- // Strip out the semicolon if it's there
- if (valueDesc.endsWith(";"))
- valueDesc = valueDesc.substring(0, valueDesc.length() - 1);
+ // Strip out the semicolon if it's there
+ if (valueDesc.endsWith(";"))
+ valueDesc = valueDesc.substring(0, valueDesc.length() - 1);
- parts.add(new CellFormatPart(locale, valueDesc));
- } catch (RuntimeException e) {
- LOG.warn("Invalid format: {}", CellFormatter.quote(m.group()), e);
- parts.add(null);
+ parts.add(new CellFormatPart(locale, valueDesc));
+ } catch (RuntimeException e) {
+ LOG.warn("Invalid format: {}", CellFormatter.quote(m.group()), e);
+ parts.add(null);
+ }
}
+ } catch (StackOverflowError e) {
+ // very complex formats can cause the regex-parsing to exceed the available stack
+ // we want to handle this more gracefully by catching it and reporting a bit more
+ // details in the error message
+ throw new IllegalStateException("The provided format is too complex: " + format +
+ ", you can try to increase Java Stack size via commandline argument '-Xss' " +
+ "to allow handling this format");
}
formatPartCount = parts.size();
assertContains(txt, "Macro2");
}
}
+
+ @Test
+ void testStackOverflowInRegex() throws IOException {
+ try (ExcelExtractor extractor = createExtractor("clusterfuzz-testcase-minimized-POIHSSFFuzzer-4657005060816896.xls")) {
+ extractor.getText();
+ } catch (IllegalStateException e) {
+ // we either get a StackOverflow or a parsing error depending on the stack-size of the current JVM,
+ // so we expect both here
+ assertTrue(e.getMessage().contains("Provided formula is too complex") ||
+ e.getMessage().contains("Did not have a ExtendedFormatRecord"));
+ }
+ }
}