Package aQute.lib.zip
Class ZipUtil
- java.lang.Object
-
- aQute.lib.zip.ZipUtil
-
public class ZipUtil extends java.lang.Object
This class provides utilities to work with zip files. http://www.opensource.apple.com/source/zip/zip-6/unzip/unzip/proginfo/extra. fld
-
-
Field Summary
Fields Modifier and Type Field Description static int
EXTID_BND
-
Constructor Summary
Constructors Constructor Description ZipUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
cleanPath(java.lang.String path)
Clean the input path to avoid ZipSlip issues.static byte[]
extraFieldFromString(byte[] extra, java.lang.String value)
Add a ZIP extra field from a String.static long
getModifiedTime(java.util.zip.ZipEntry entry)
static boolean
isCompromised(java.lang.String path)
static void
setModifiedTime(java.util.zip.ZipEntry entry, long utc)
static java.lang.String
stringFromExtraField(byte[] extra)
Extract a String from a ZIP extra field.
-
-
-
Field Detail
-
EXTID_BND
public static final int EXTID_BND
- See Also:
- Constant Field Values
-
-
Method Detail
-
getModifiedTime
public static long getModifiedTime(java.util.zip.ZipEntry entry)
-
setModifiedTime
public static void setModifiedTime(java.util.zip.ZipEntry entry, long utc)
-
cleanPath
public static java.lang.String cleanPath(java.lang.String path)
Clean the input path to avoid ZipSlip issues.All double '/', '.' and '..' path entries are resolved and removed. The returned path will have a '/' at the end when the input path has a '/' at the end. A leading '/' is stripped. An empty string is unmodified.
- Parameters:
path
- ZipEntry path. Must not benull
.- Returns:
- Cleansed ZipEntry path.
- Throws:
java.io.UncheckedIOException
- If the entry used '..' relative paths to back up past the start of the path.
-
isCompromised
public static boolean isCompromised(java.lang.String path)
-
extraFieldFromString
public static byte[] extraFieldFromString(byte[] extra, java.lang.String value)
Add a ZIP extra field from a String.The String is UTF-8 encoded and the extra field uses the Header ID
EXTID_BND
.- Parameters:
extra
- The extra field to modify by adding or replacing theEXTID_BND
header. May benull
.value
- The String value to be contained in the ZIP extra field.- Returns:
- A ZIP extra field including the
EXTID_BND
header with the UTF-8 encoded String. - See Also:
- Section 4.5 - Extensible data fields
-
stringFromExtraField
public static java.lang.String stringFromExtraField(byte[] extra)
Extract a String from a ZIP extra field.The Header ID
EXTID_BND
is searched for in the specified extra field. If found, the UTF-8 encoded value is converted to a String and returned.If the specified extra field is not valid, the extra field is considered to be a UTF-8 encoded value and is converted to a String and returned.
- Returns:
- The String value contained in the ZIP extra field or
null
is there is noEXTID_BND
Header ID and the ZIP extra field data is not invalid. - See Also:
- Section 4.5 - Extensible data fields
-
-