You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2021/09/22 02:17:12 UTC

[Bug 65586] New: JarContents#mightContainResource doesn't return true when found directory in jar file by using bloom filter

https://bz.apache.org/bugzilla/show_bug.cgi?id=65586

            Bug ID: 65586
           Summary: JarContents#mightContainResource doesn't return true
                    when found directory in jar file by using bloom filter
           Product: Tomcat 9
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: digitalcat@huawei.com
  Target Milestone: -----

Dear all

When using a bloom filter to speed up archive lookups
(useBloomFilterForArchives = "true" in context.xml) in Tomcat9, tomcat will
fail to get resources from jar file in some special condition.

For example , when we want to find a directory resource in xxx.jar by using a
bloom filter,

if we use " cl.getResouce("/org/apache/coyote", "/WEB-INF/classes") " to get
resources , noting will be returned,  
(By the way,
we find the same way to be used to get resources in the xmlbeans-4.0.0.jar
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl#isPath30)

but if we use cl.getResouce("/org/apache/coyote/", "/WEB-INF/classes") , it
will return the resources we want successfully.

if we do not use bloomFilter , both ways will return resources successfully. 

It is cause by org.apache.catalina.webresources.JarContents#JarContents who
create hashCode of JarEntry.getName(), if JarEntry is directory, its name
contain

"/" at the last of string. 

So when you use param didn't contain "/" at last,
org.apache.catalina.webresources.JarContents#mightContainResource will return
false.

For example:

        JarFile jarFile = new JarFile("D:\\tomcat-coyote.jar");

        JarContents jarContents  = new JarContents(jarFile);

        // false
    
System.out.println(jarContents.mightContainResource("/org/apache/catalina",
"/WEB-INF/classes"));

        // true
   
System.out.println(jarContents.mightContainResource("/org/apache/catalina/",
"/WEB-INF/classes"));

So I suggest changing JarContents#hashcode like this to ignore end slash of
path

    private int hashcode(String content, int startPos, int hashPrime) {
        int h = hashPrime/2;
        int contentLength = content.length();

        if (contentLength > 1 && content.charAt(contentLength - 1) == '/') {
            // ignore end slash
            contentLength--;
        }

        for (int i = startPos; i < contentLength; i++) {
            h = hashPrime * h + content.charAt(i);
        }

        if (h < 0) {
            h = h * -1;
        }
        return h;
    }



sorry ,I am not native speaker , hope that I made it clear!

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 65586] JarContents#mightContainResource doesn't return true when finding directory in jar file by using bloom filter

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65586

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Mark Thomas <ma...@apache.org> ---
Fixed in:
- 10.1.x for 10.1.0-M6 onwards
- 10.0.x for 10.0.12 onwards
- 9.0.x for 9.0.54 onwards

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 65586] JarContents#mightContainResource doesn't return true when finding directory in jar file by using bloom filter

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65586

--- Comment #1 from Mark Thomas <ma...@apache.org> ---
That is a very clear description. Thank you. I am working on a fix now.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 65586] JarContents#mightContainResource doesn't return true when finding directory in jar file by using bloom filter

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65586

DigitalCat <di...@huawei.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|JarContents#mightContainRes |JarContents#mightContainRes
                   |ource doesn't return true   |ource doesn't return true
                   |when found directory in jar |when finding directory in
                   |file by using bloom filter  |jar file by using bloom
                   |                            |filter

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org