pjfanning commented on code in PR #1525:
URL: https://github.com/apache/poi/pull/1525#discussion_r4466611614
##########
poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackagePartCollection.java:
##########
@@ -42,4 +51,43 @@ void testPackagePartCollection_64473() throws Exception {
}
}
+ /**
+ * Checking rule M1.11 used to build and look up every prefix of a part
name,
+ * which is quadratic in the length of deeply nested names
+ */
+ @Test
+ void testDeeplyNestedPartNames() throws Exception {
+ UnsynchronizedByteArrayOutputStream bos =
UnsynchronizedByteArrayOutputStream.builder().get();
+ try (ZipOutputStream zos = new ZipOutputStream(bos)) {
+ zos.putNextEntry(new ZipEntry("[Content_Types].xml"));
+ zos.write(("<Types
xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">" +
+ "<Default Extension=\"xml\"
ContentType=\"application/xml\"/></Types>").getBytes(StandardCharsets.UTF_8));
+ String folder = "a/".repeat(30_000);
+ for (int i = 0; i < 20; i++) {
+ zos.putNextEntry(new ZipEntry(folder + i + ".xml"));
+ zos.write("<x/>".getBytes(StandardCharsets.UTF_8));
+ }
+ }
+
+ int parts = assertTimeoutPreemptively(Duration.ofSeconds(10), () -> {
Review Comment:
Pushed fe54a35fa0, which removes the `comparedChars` counter from the class.
It was only read by the test and only counted work inside `containsPrefixOf`,
so it couldn't see slow paths elsewhere on the open route.
`testDeeplyNestedPartNames` now opens a real package, decoy names included,
under a 60 s timeout. That took about 10 s here for the whole test, and about
240 s with trunk's `PackagePartCollection`, so the margin holds on both sides.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]