This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 6ae1a90 Fix BZ 65586 - Correct bloom filter lookups for directories
with final /
6ae1a90 is described below
commit 6ae1a90d2354b68920de1cab33db4c7a3b7be8f1
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Sep 27 21:38:49 2021 +0100
Fix BZ 65586 - Correct bloom filter lookups for directories with final /
https://bz.apache.org/bugzilla/show_bug.cgi?id=65586
---
.../apache/catalina/webresources/JarContents.java | 17 +++++++-
.../TestAbstractArchiveResourceSet.java | 49 ++++++++++++++++++++++
.../webresources/TesterWebResourceRoot.java | 3 +-
test/org/apache/tomcat/unittest/TesterContext.java | 9 +++-
webapps/docs/changelog.xml | 6 +++
5 files changed, 79 insertions(+), 5 deletions(-)
diff --git a/java/org/apache/catalina/webresources/JarContents.java
b/java/org/apache/catalina/webresources/JarContents.java
index c7da5e2..0afa9fa 100644
--- a/java/org/apache/catalina/webresources/JarContents.java
+++ b/java/org/apache/catalina/webresources/JarContents.java
@@ -78,6 +78,16 @@ public final class JarContents {
bits1.set(pathHash1 % TABLE_SIZE);
bits2.set(pathHash2 % TABLE_SIZE);
+
+ // While directory entry names always end in "/", application code
+ // may look them up without the trailing "/". Add this second form.
+ if (entry.isDirectory()) {
+ pathHash1 = hashcode(name, startPos, name.length() - 1,
HASH_PRIME_1);
+ pathHash2 = hashcode(name, startPos, name.length() - 1,
HASH_PRIME_2);
+
+ bits1.set(pathHash1 % TABLE_SIZE);
+ bits2.set(pathHash2 % TABLE_SIZE);
+ }
}
}
@@ -92,9 +102,12 @@ public final class JarContents {
* @return hashcode of the range.
*/
private int hashcode(String content, int startPos, int hashPrime) {
+ return hashcode(content, startPos, content.length(), hashPrime);
+ }
+
+ private int hashcode(String content, int startPos, int endPos, int
hashPrime) {
int h = hashPrime/2;
- int contentLength = content.length();
- for (int i = startPos; i < contentLength; i++) {
+ for (int i = startPos; i < endPos; i++) {
h = hashPrime * h + content.charAt(i);
}
diff --git
a/test/org/apache/catalina/webresources/TestAbstractArchiveResourceSet.java
b/test/org/apache/catalina/webresources/TestAbstractArchiveResourceSet.java
new file mode 100644
index 0000000..7c5b2f2
--- /dev/null
+++ b/test/org/apache/catalina/webresources/TestAbstractArchiveResourceSet.java
@@ -0,0 +1,49 @@
+/*
+ * 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.catalina.webresources;
+
+import java.io.File;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.catalina.WebResource;
+import org.apache.catalina.WebResourceRoot;
+
+public class TestAbstractArchiveResourceSet {
+
+ /*
+ * https://bz.apache.org/bugzilla/show_bug.cgi?id=65586
+ */
+ @Test
+ public void testBloomFilterWithDirectory() {
+ WebResourceRoot root = new TesterWebResourceRoot();
+
+ root.getContext().setUseBloomFilterForArchives(true);
+
+ File file = new
File("webapps/examples/WEB-INF/lib/taglibs-standard-impl-1.2.5-migrated-0.0.1.jar");
+
+ JarResourceSet jarResourceSet = new JarResourceSet(root,
"/WEB-INF/classes", file.getAbsolutePath(), "/");
+ jarResourceSet.getArchiveEntries(false);
+
+ WebResource r1 = jarResourceSet.getResource("/WEB-INF/classes/org/");
+ Assert.assertTrue(r1.isDirectory());
+
+ WebResource r2 = jarResourceSet.getResource("/WEB-INF/classes/org");
+ Assert.assertTrue(r2.isDirectory());
+ }
+}
diff --git a/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
b/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
index 6217f26..a56186e 100644
--- a/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
+++ b/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
@@ -80,9 +80,10 @@ public class TesterWebResourceRoot extends StandardRoot {
return null;
}
+ Context context = new TesterContext();
@Override
public Context getContext() {
- return new TesterContext();
+ return context;
}
@Override
diff --git a/test/org/apache/tomcat/unittest/TesterContext.java
b/test/org/apache/tomcat/unittest/TesterContext.java
index 996f2f6..a62da15 100644
--- a/test/org/apache/tomcat/unittest/TesterContext.java
+++ b/test/org/apache/tomcat/unittest/TesterContext.java
@@ -1305,10 +1305,15 @@ public class TesterContext implements Context {
@Override
public void setParallelAnnotationScanning(boolean
parallelAnnotationScanning) {}
+ boolean useBloomFilterForArchives = false;
@Override
- public boolean getUseBloomFilterForArchives() { return false; }
+ public boolean getUseBloomFilterForArchives() {
+ return useBloomFilterForArchives;
+ }
@Override
- public void setUseBloomFilterForArchives(boolean
useBloomFilterForArchives) {}
+ public void setUseBloomFilterForArchives(boolean
useBloomFilterForArchives) {
+ this.useBloomFilterForArchives = useBloomFilterForArchives;
+ }
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index a8dc92f..9a0cbda 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -115,6 +115,12 @@
Fix delete then create object manipulations with
<code>DataSourceUserDatabase</code>. (remm)
</fix>
+ <fix>
+ <bug>65586</bug>: Fix the bloom filter used to improve performance of
+ archive file look ups in the web resources implementation so it works
+ correctly for directory lookups whether or not the provided directory
+ name includes the trailing <code>/</code>. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]