[Bug 394064] ensure that JarFile instances are closed on JarFileResource.release()
This commit is contained in:
parent
2581eb130a
commit
cf98276b32
|
@ -65,6 +65,19 @@ class JarFileResource extends JarResource
|
|||
_list=null;
|
||||
_entry=null;
|
||||
_file=null;
|
||||
|
||||
if ( _jarFile != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
_jarFile.close();
|
||||
}
|
||||
catch ( IOException ioe )
|
||||
{
|
||||
LOG.ignore(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
_jarFile=null;
|
||||
super.release();
|
||||
}
|
||||
|
@ -166,7 +179,7 @@ class JarFileResource extends JarResource
|
|||
if (jarFile!=null && _entry==null && !_directory)
|
||||
{
|
||||
// OK - we have a JarFile, lets look at the entries for our path
|
||||
Enumeration e=jarFile.entries();
|
||||
Enumeration<JarEntry> e=jarFile.entries();
|
||||
while(e.hasMoreElements())
|
||||
{
|
||||
JarEntry entry = (JarEntry) e.nextElement();
|
||||
|
@ -301,12 +314,11 @@ class JarFileResource extends JarResource
|
|||
}
|
||||
}
|
||||
|
||||
Enumeration e=jarFile.entries();
|
||||
Enumeration<JarEntry> e=jarFile.entries();
|
||||
String dir=_urlString.substring(_urlString.indexOf("!/")+2);
|
||||
while(e.hasMoreElements())
|
||||
{
|
||||
|
||||
JarEntry entry = (JarEntry) e.nextElement();
|
||||
JarEntry entry = e.nextElement();
|
||||
String name=entry.getName().replace('\\','/');
|
||||
if(!name.startsWith(dir) || name.length()==dir.length())
|
||||
{
|
||||
|
|
|
@ -35,8 +35,11 @@ import java.util.Date;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.toolchain.test.OS;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
|
@ -125,14 +128,14 @@ public class ResourceTest
|
|||
URI uri = file.toURI();
|
||||
__userURL=uri.toURL();
|
||||
|
||||
__userURL = new URL(__userURL.toString() + "src/test/java/org/eclipse/jetty/util/resource/");
|
||||
FilePermission perm = (FilePermission) __userURL.openConnection().getPermission();
|
||||
__userDir = new File(perm.getName()).getCanonicalPath() + File.separatorChar;
|
||||
__relDir = "src/test/java/org/eclipse/jetty/util/resource/".replace('/', File.separatorChar);
|
||||
__userURL = MavenTestingUtils.getTestResourcesDir().toURI().toURL();
|
||||
FilePermission perm = (FilePermission) __userURL.openConnection().getPermission();
|
||||
__userDir = new File(perm.getName()).getCanonicalPath() + File.separatorChar;
|
||||
__relDir = "src/test/resources/".replace('/', File.separatorChar);
|
||||
|
||||
System.err.println("User Dir="+__userDir);
|
||||
System.err.println("Rel Dir="+__relDir);
|
||||
System.err.println("User URL="+__userURL);
|
||||
//System.err.println("User Dir="+__userDir);
|
||||
//System.err.println("Rel Dir="+__relDir);
|
||||
//System.err.println("User URL="+__userURL);
|
||||
|
||||
tmpFile=File.createTempFile("test",null).getCanonicalFile();
|
||||
tmpFile.deleteOnExit();
|
||||
|
@ -146,15 +149,15 @@ public class ResourceTest
|
|||
data[i++]=new Data(__userURL,EXISTS,DIR);
|
||||
data[i++]=new Data(__userDir,EXISTS,DIR);
|
||||
data[i++]=new Data(__relDir,EXISTS,DIR);
|
||||
data[i++]=new Data(__userURL+"ResourceTest.java",EXISTS,!DIR);
|
||||
data[i++]=new Data(__userDir+"ResourceTest.java",EXISTS,!DIR);
|
||||
data[i++]=new Data(__relDir+"ResourceTest.java",EXISTS,!DIR);
|
||||
data[i++]=new Data(__userURL+"jetty-logging.properties",EXISTS,!DIR);
|
||||
data[i++]=new Data(__userDir+"jetty-logging.properties",EXISTS,!DIR);
|
||||
data[i++]=new Data(__relDir+"jetty-logging.properties",EXISTS,!DIR);
|
||||
data[i++]=new Data(__userURL+"NoName.txt",!EXISTS,!DIR);
|
||||
data[i++]=new Data(__userDir+"NoName.txt",!EXISTS,!DIR);
|
||||
data[i++]=new Data(__relDir+"NoName.txt",!EXISTS,!DIR);
|
||||
|
||||
data[i++]=new Data(data[rt],"ResourceTest.java",EXISTS,!DIR);
|
||||
data[i++]=new Data(data[rt],"/ResourceTest.java",EXISTS,!DIR);
|
||||
data[i++]=new Data(data[rt],"jetty-logging.properties",EXISTS,!DIR);
|
||||
data[i++]=new Data(data[rt],"/jetty-logging.properties",EXISTS,!DIR);
|
||||
data[i++]=new Data(data[rt],"NoName.txt",!EXISTS,!DIR);
|
||||
data[i++]=new Data(data[rt],"/NoName.txt",!EXISTS,!DIR);
|
||||
|
||||
|
@ -327,15 +330,14 @@ public class ResourceTest
|
|||
{
|
||||
String s = "jar:"+__userURL+"TestData/test.zip!/subdir/numbers";
|
||||
|
||||
// TODO move this into src/test/resources!!!
|
||||
ZipFile zf = new ZipFile(MavenTestingUtils.getProjectFile("src/test/java/org/eclipse/jetty/util/resource/TestData/test.zip"));
|
||||
ZipFile zf = new ZipFile(MavenTestingUtils.getTestResourceFile("TestData/test.zip"));
|
||||
|
||||
long last = zf.getEntry("subdir/numbers").getTime();
|
||||
|
||||
Resource r = Resource.newResource(s);
|
||||
assertEquals(last,r.lastModified()); // Known date value inside zip
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Test
|
||||
public void testJarFileCopyToDirectoryTraversal () throws Exception
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
Manifest-Version: 1.0
|
||||
Created-By: 1.2.2 (Sun Microsystems Inc.)
|
||||
|
|
@ -0,0 +1 @@
|
|||
ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
|
@ -0,0 +1 @@
|
|||
1234567890
|
|
@ -0,0 +1 @@
|
|||
ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
|
@ -0,0 +1 @@
|
|||
1234567890
|
|
@ -0,0 +1 @@
|
|||
ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
|
@ -0,0 +1 @@
|
|||
1234567890
|
|
@ -60,10 +60,14 @@ public abstract class Descriptor
|
|||
|
||||
if (_root == null)
|
||||
{
|
||||
//boolean oldValidating = _processor.getParser().getValidating();
|
||||
//_processor.getParser().setValidating(_validating);
|
||||
_root = _parser.parse(_xml.getURL().toString());
|
||||
//_processor.getParser().setValidating(oldValidating);
|
||||
try
|
||||
{
|
||||
_root = _parser.parse(_xml.getInputStream());
|
||||
}
|
||||
finally
|
||||
{
|
||||
_xml.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue