[jcifs] Fix for handing file names that start with .# and ..#

Jim Hurne hurne at vivisimo.com
Wed Sep 1 13:34:35 MDT 2010


Hello Mike, 

We found a bug in JCIF that breaks support for file names that start with ".#" and "..#", and we developed a patch (see attached). 

The bug is a direct result of the differences between how java.net.URL and java.net.URLStreamHandler parse URLs (or put another way, a direct result of the differences between smb URLs and http URLs). Everything works fine if the URL is constructed without a context (parent). However, when construcing a URL with a parent, the "." and ".." (of .# and ..#) are treated as relative path specifiers. This is becuase everything after the hash is treated as a ref (anchor), and when the ref is removed, all that is left is the "." and "..". 

Examples: 

jcifs.Config.registerSmbURLHandler(); 

// Works fine 
URL url = new URL("smb://some-share/dir/..#twodots"); 
// prints out "url: smb://some-share/dir/..#twodots " 
System.out.println("url: " + url.toString()); 

// Does NOT work 
URL parent = new URL("smb://some-share/dir/"); 
url = new URL(parent, "..#twodots"); 

// prints out "url: smb://some-share/#twodots" <-- WRONG, notice that "/dir" is missing from the path, and how the ".." is missing 
System.out.println("url: " + url.toString()); 

The problem affects not just URLs, but also SmbFile instances (since all of the constructors ultimately create a URL). The patch adds some handing for these special casses to the jcifs.smb.Handler class. 

In addition to the patch (which was developed against JCIFS 1.3.14), I've included a JUnit 4 Parameterized test that exercises many more examples of the problem. We used the JUnit test class to validate that our patch works. It's easy to add additional tests, so if there is any inputs that you think we should test (to make sure that our patch doesn't break any existing functionality), let us know and we'll add them. 

Regards, 

Jim Hurne | Software Engineer 
Office: +1.412.422.2499 | Mobile: +1.724.683.1500 
1710 Murray Avenue, Pittsburgh PA 15217 USA 
hurne at vivisimo.com | Connect: www.vivisimo.com 
Vivisimo - Information Optimized 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.samba.org/pipermail/jcifs/attachments/20100901/9903a57a/attachment.html>


More information about the jCIFS mailing list