Package net.sourceforge.jnlp.util
Class JarFile
- java.lang.Object
-
- net.sourceforge.jnlp.util.JarFile
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class JarFile extends java.lang.Object implements java.io.CloseableA wrapper overJarFilethat verifies zip headers to protect against GIFAR attacks.- See Also:
- Gifar
-
-
Field Summary
Fields Modifier and Type Field Description private LazyLoaded<java.lang.reflect.Constructor<java.util.jar.JarFile>>constructorprivate java.util.jar.JarFiledelegateprivate static intHEADER_LENGTHprivate static booleanJAVA9_OR_GREATERprivate LazyLoaded<java.lang.Object>runtimeVersionprivate static byte[]ZIP_ENTRY_HEADER_SIGNATUREThe ZIP specification requires that the zip header for all entries in a zip-compressed archive must start with a well known "PK" which is defined as hex x50 x4b x03 x04.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()private java.util.jar.JarFilecreateDelegate(java.io.File file)java.util.Enumeration<java.util.jar.JarEntry>entries()java.io.InputStreamgetInputStream(java.util.jar.JarEntry je)java.util.jar.ManifestgetManifest()java.util.jar.JarFilegetNative()private voidverifyZipHeader(java.io.File file)Verify the header for the zip entry.
-
-
-
Field Detail
-
JAVA9_OR_GREATER
private static final boolean JAVA9_OR_GREATER
-
runtimeVersion
private final LazyLoaded<java.lang.Object> runtimeVersion
-
constructor
private final LazyLoaded<java.lang.reflect.Constructor<java.util.jar.JarFile>> constructor
-
delegate
private final java.util.jar.JarFile delegate
-
ZIP_ENTRY_HEADER_SIGNATURE
private static final byte[] ZIP_ENTRY_HEADER_SIGNATURE
The ZIP specification requires that the zip header for all entries in a zip-compressed archive must start with a well known "PK" which is defined as hex x50 x4b x03 x04.Note - this is not file-header, it is item-header.
Actually most of compressing formats have some n-bytes headers. Eg: http://www.gzip.org/zlib/rfc-gzip.html#header-trailer for ID1 and ID2 so in case that some differently compressed jars will come to play, this is the place where to fix it.
- See Also:
- ZIP Specification
-
HEADER_LENGTH
private static final int HEADER_LENGTH
-
-
Method Detail
-
createDelegate
private java.util.jar.JarFile createDelegate(java.io.File file) throws java.io.IOException- Throws:
java.io.IOException
-
getManifest
public java.util.jar.Manifest getManifest() throws java.io.IOException- Throws:
java.io.IOException
-
entries
public java.util.Enumeration<java.util.jar.JarEntry> entries()
-
getInputStream
public java.io.InputStream getInputStream(java.util.jar.JarEntry je) throws java.io.IOException- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
getNative
public java.util.jar.JarFile getNative()
-
verifyZipHeader
private void verifyZipHeader(java.io.File file) throws java.io.IOExceptionVerify the header for the zip entry.Although zip specification allows to skip all corrupted entries, it is not safe for jars since it allows a different format to fake itself as a Jar.
- Throws:
java.io.IOException
-
-