Package aQute.lib.zip

Class ZipUtil

java.lang.Object
aQute.lib.zip.ZipUtil

public class ZipUtil extends 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 Details

  • Constructor Details

    • ZipUtil

      public ZipUtil()
  • Method Details

    • getModifiedTime

      public static long getModifiedTime(ZipEntry entry)
    • setModifiedTime

      public static void setModifiedTime(ZipEntry entry, long utc)
    • cleanPath

      public static String cleanPath(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 be null.
      Returns:
      Cleansed ZipEntry path.
      Throws:
      UncheckedIOException - If the entry used '..' relative paths to back up past the start of the path.
    • isCompromised

      public static boolean isCompromised(String path)
    • extraFieldFromString

      public static byte[] extraFieldFromString(byte[] extra, 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 the EXTID_BND header. May be null.
      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:
    • stringFromExtraField

      public static 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 no EXTID_BND Header ID and the ZIP extra field data is not invalid.
      See Also: