This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 579594e465 Tweak the bloom filter for the root
579594e465 is described below
commit 579594e4659f9c3578d5bb0a06e00012beae0e25
Author: remm <[email protected]>
AuthorDate: Fri Aug 28 11:40:31 2026 +0200
Tweak the bloom filter for the root
It's best to return true when in doubt.
Test written using OpenCode.
---
java/org/apache/catalina/webresources/JarContents.java | 7 ++++---
.../apache/catalina/webresources/TestJarContents.java | 18 +++++++++++++-----
.../catalina/webresources/TestJarResourceSet.java | 15 +++++++++++++++
.../catalina/webresources/TestJarResourceSetMount.java | 17 +++++++++++++++++
4 files changed, 49 insertions(+), 8 deletions(-)
diff --git a/java/org/apache/catalina/webresources/JarContents.java
b/java/org/apache/catalina/webresources/JarContents.java
index 79045c7120..c338e085b2 100644
--- a/java/org/apache/catalina/webresources/JarContents.java
+++ b/java/org/apache/catalina/webresources/JarContents.java
@@ -155,11 +155,12 @@ public final class JarContents {
if (path.startsWith(webappRoot)) {
startPos = webappRoot.length();
}
-
- if (path.charAt(startPos) == '/') {
- // ignore leading slash
+ while (startPos < path.length() && path.charAt(startPos) == '/') {
startPos++;
}
+ if (startPos == path.length()) {
+ return true; // archive root: cannot rule out
+ }
// calculate the hash lazily and return a boolean value for this path
return (bits1.get(hashcode(path, startPos, HASH_PRIME_1) % TABLE_SIZE)
&&
diff --git a/test/org/apache/catalina/webresources/TestJarContents.java
b/test/org/apache/catalina/webresources/TestJarContents.java
index d5c1c17385..8fff9bb6f2 100644
--- a/test/org/apache/catalina/webresources/TestJarContents.java
+++ b/test/org/apache/catalina/webresources/TestJarContents.java
@@ -69,17 +69,25 @@ public class TestJarContents {
Assert.assertFalse(testJarContentsObject.mightContainResource(
"/d7/d1-f1.txt", jar.getAbsolutePath()));
- Assert.assertFalse(testJarContentsObject.mightContainResource(
+ // A path that only contains slashes (once the webapp root and any
+ // leading slashes have been removed) refers to the root of the
+ // archive. That cannot be ruled out, so the method must return
+ // true.
+ Assert.assertTrue(testJarContentsObject.mightContainResource(
"/", jar.getAbsolutePath()));
- Assert.assertFalse(testJarContentsObject.mightContainResource(
+ Assert.assertTrue(testJarContentsObject.mightContainResource(
"/////", jar.getAbsolutePath()));
+ Assert.assertTrue(testJarContentsObject.mightContainResource(
+ jar.getAbsolutePath(), jar.getAbsolutePath()));
}
- @Test(expected = StringIndexOutOfBoundsException.class)
- public void testStringOutOfBoundExceptions() {
- testJarContentsObject.mightContainResource("", jar.getAbsolutePath());
+ @Test
+ public void testEmptyPath() {
+ // Must not throw and must return true since nothing can be ruled
+ // out.
+ Assert.assertTrue(testJarContentsObject.mightContainResource("",
jar.getAbsolutePath()));
}
@Test(expected = NullPointerException.class)
diff --git a/test/org/apache/catalina/webresources/TestJarResourceSet.java
b/test/org/apache/catalina/webresources/TestJarResourceSet.java
index 8aa14c96aa..641fc1735b 100644
--- a/test/org/apache/catalina/webresources/TestJarResourceSet.java
+++ b/test/org/apache/catalina/webresources/TestJarResourceSet.java
@@ -18,8 +18,10 @@ package org.apache.catalina.webresources;
import java.io.File;
+import org.junit.Assert;
import org.junit.Test;
+import org.apache.catalina.WebResource;
import org.apache.catalina.WebResourceRoot;
import org.apache.catalina.WebResourceSet;
@@ -52,6 +54,19 @@ public class TestJarResourceSet extends
AbstractTestResourceSet {
Object obj = new JarResourceSet();
}
+ @Test
+ public void testGetResourceRootAfterBloomFilterBuilt() {
+ // Regression test: the archive root must still be found once the
+ // archive (and therefore the bloom filter) has been opened by a
+ // previous lookup.
+ WebResource file = resourceRoot.getResource("/d1/d1-f1.txt");
+ Assert.assertTrue(file.isFile());
+ WebResource webResource = resourceRoot.getResource("/");
+ Assert.assertTrue(webResource.isDirectory());
+ Assert.assertEquals("", webResource.getName());
+ Assert.assertEquals("/", webResource.getWebappPath());
+ }
+
@Override
protected String getNewDirName() {
return "test-dir-08";
diff --git a/test/org/apache/catalina/webresources/TestJarResourceSetMount.java
b/test/org/apache/catalina/webresources/TestJarResourceSetMount.java
index 31a04cdedc..41b1b55dc2 100644
--- a/test/org/apache/catalina/webresources/TestJarResourceSetMount.java
+++ b/test/org/apache/catalina/webresources/TestJarResourceSetMount.java
@@ -18,6 +18,10 @@ package org.apache.catalina.webresources;
import java.io.File;
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.catalina.WebResource;
import org.apache.catalina.WebResourceRoot;
import org.apache.catalina.WebResourceSet;
@@ -57,4 +61,17 @@ public class TestJarResourceSetMount extends
AbstractTestResourceSetMount {
protected String getNewFileName() {
return "test-file-10";
}
+
+ @Test
+ public void testGetResourceRootAfterBloomFilterBuilt() {
+ // Regression test: the mount root must still be found, without
+ // throwing, once the archive (and therefore the bloom filter) has
+ // been opened by a previous lookup.
+ WebResource file = resourceRoot.getResource(getMount() +
"/d1/d1-f1.txt");
+ Assert.assertTrue(file.isFile());
+ WebResource webResource = resourceRoot.getResource(getMount());
+ Assert.assertTrue(webResource.isDirectory());
+ Assert.assertEquals("mount", webResource.getName());
+ Assert.assertEquals(getMountPath() + "/", webResource.getWebappPath());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]