This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi-xmlbeans.git
The following commit(s) were added to refs/heads/trunk by this push:
new 70d618c4 stop the jar parent-path loop in StscImporter.resolve (#138)
70d618c4 is described below
commit 70d618c4f17a7cb33543189d2ff325a7b72cde3e
Author: aizu-m <[email protected]>
AuthorDate: Sun Oct 18 18:47:47 2026 +0530
stop the jar parent-path loop in StscImporter.resolve (#138)
---
.../apache/xmlbeans/impl/schema/StscImporter.java | 8 ++-
.../impl/schema/StscImporterResolveTest.java | 68 ++++++++++++++++++++++
2 files changed, 73 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/xmlbeans/impl/schema/StscImporter.java
b/src/main/java/org/apache/xmlbeans/impl/schema/StscImporter.java
index 95532835..288ac6fc 100644
--- a/src/main/java/org/apache/xmlbeans/impl/schema/StscImporter.java
+++ b/src/main/java/org/apache/xmlbeans/impl/schema/StscImporter.java
@@ -246,10 +246,12 @@ public class StscImporter {
int slashDotDotIndex = r.indexOf("/..", exclPointSlashIndex);
while (slashDotDotIndex > 0) {
int prevSlashIndex = r.lastIndexOf("/", slashDotDotIndex -
1);
- if (prevSlashIndex >= exclPointSlashIndex) {
- String temp = r.substring(slashDotDotIndex + 3);
- r = r.substring(0, prevSlashIndex).concat(temp);
+ if (prevSlashIndex < exclPointSlashIndex) {
+ // ".." above the root of the jar, leave it unresolved
+ break;
}
+ String temp = r.substring(slashDotDotIndex + 3);
+ r = r.substring(0, prevSlashIndex).concat(temp);
slashDotDotIndex = r.indexOf("/..", exclPointSlashIndex);
}
}
diff --git
a/src/test/java/org/apache/xmlbeans/impl/schema/StscImporterResolveTest.java
b/src/test/java/org/apache/xmlbeans/impl/schema/StscImporterResolveTest.java
new file mode 100644
index 00000000..77097a10
--- /dev/null
+++ b/src/test/java/org/apache/xmlbeans/impl/schema/StscImporterResolveTest.java
@@ -0,0 +1,68 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.xmlbeans.impl.schema;
+
+import org.apache.xmlbeans.XmlBeans;
+import org.apache.xmlbeans.XmlError;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.junit.jupiter.api.Test;
+
+import java.net.URI;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+
+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.assertTimeoutPreemptively;
+
+public class StscImporterResolveTest {
+
+ private static final URI JAR_BASE =
URI.create("jar:file:/tmp/schemas.jar!/xsd/a.xsd");
+
+ @Test
+ void resolvesParentInsideJar() throws Exception {
+ assertEquals("jar:file:/tmp/schemas.jar!/common/b.xsd",
+ StscImporter.resolve(JAR_BASE, "../common/b.xsd").toString());
+ }
+
+ @Test
+ void parentAboveJarRootTerminates() {
+ assertTimeoutPreemptively(Duration.ofSeconds(10), () ->
+ StscImporter.resolve(JAR_BASE, "../../b.xsd"));
+ }
+
+ @Test
+ void compileWithImportAboveJarRootTerminates() throws Exception {
+ String xsd =
+ "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'
targetNamespace='urn:a'>" +
+ "<xs:import namespace='urn:b' schemaLocation='../../b.xsd'/>" +
+ "</xs:schema>";
+ XmlOptions parseOpts = new
XmlOptions().setDocumentSourceName(JAR_BASE.toString());
+ XmlObject schema = XmlObject.Factory.parse(xsd, parseOpts);
+
+ List<XmlError> errors = new ArrayList<>();
+ XmlOptions compileOpts = new XmlOptions().setErrorListener(errors);
+ assertTimeoutPreemptively(Duration.ofSeconds(10), () ->
+ assertThrows(XmlException.class, () ->
+ XmlBeans.compileXsd(new XmlObject[]{schema},
XmlBeans.getBuiltinTypeSystem(), compileOpts)));
+ assertFalse(errors.isEmpty());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]