How to unzip an archive with absolute paths?

250 views Asked by At

I have a ZIP file that was obtained from https://highlightjs.org/download - for some inexplicable reason it has absolute pathnames in it:

$ unzip -l highlight.zip
Archive:  highlight.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
    38854  08-10-23 22:10   /DIGESTS.md
     1514  08-10-23 22:10   /LICENSE
     1717  08-10-23 22:10   /README.md
        0  08-10-23 22:10   /es/
    76121  08-10-23 22:10   /es/core.js
...

It obviously fails to extract, giving unzip: skipping insecure entry errors. Is there any way to override this, e.g. tar can simply remove the leading / and extract the file as a relative path.

UPDATE:

Using FreeBSD 13.2 /usr/bin/unzip (has no way to see the version)

1

There are 1 answers

5
Mark Adler On

You must have an old version of unzip. Mine (6.0) strips the leading slash, issues a warning, and proceeds to extract into the current directory:

Archive:  ../highlight.zip
warning:  stripped absolute path spec from /DIGESTS.md
 extracting: DIGESTS.md              

I'd recommend that you update your unzip, which will make your life better in many ways.

You should also let the maintainers of that web site know that their zip files are rude.