90.4. unzip-6.0
ZIP extraction utilities
| Version | 6.0, release 2 |
| Shelf | archiver — Compression libraries and archive tools |
| Phase | 41_system (System), 59 of 1047 in build order |
| Licence | Info-ZIP |
| Homepage | https://infozip.sourceforge.net/UnZip.html |
| Build time | 0.1 SBU |
| Installed size | 663.7 KiB in 12 files |
| Recipe | ports/core/archiver/unzip/kpkgbuild |
About
UnZip is Info-ZIP’s extractor: unzip, unzipsfx, funzip, zipinfo and the zipgrep script. It is the command a user extracts a ZIP archive with, and many ports name it in depends; noto-fonts and josm, for example, unpack ZIP archives with it in their build.sh.
Info-ZIP has made no release since this version, so every fix since exists only as a distribution’s patch. The numbered series beside the recipe is Alpine’s, applied in Alpine’s order, which the numbers keep: each patch is a diff from the top of the tree and may depend on the ones before it. It carries the CVE fixes for heap and buffer overflows and the check that refuses a “zip bomb” built from overlapping entries.
Sources
unzip-6.0.tar.gz(1.3 MiB)
sha256036d96991646d0449ed0aa952e4fbe21b476ce994abc276e49d30e686708bd37
upstream: https://downloads.sourceforge.net/infozip/unzip60.tar.gz
archive copy: sources-1/archiver--unzip-6.0.tar.gz
Dependencies
Depends on: bzip2.
Required by (24): antlr2, ark, convertlit, digital, docx2txt, firefox-esr, josm, libreoffice, librepcb, librewolf, logisim-evolution, meshtastic-firmware, noto-cjk, noto-fonts, noto-fonts-extra, openjdk, openrct2, polyclipping, srb2, thunderbird, ttf-jetbrains-mono, wine-gecko, xonotic, xonotic-data.
Patches
build.sh applies these; kpkg applies nothing by itself.
01-allow-greater-hostver-values.patch— zipinfo.c: Do not crash when hostver byte is >= 10002-unzip-handle-pkware-verify.patch— Handle the PKWare verification bit of internal attributes03-remove-build-date.patch— Remove build dateIn order to make unzip build reproducibly, we remove the (already optional) build date from the binary.
04-unzip-uidgid-fix.patch— Restore uid and gid information when requested05-fix-warning-messages-on-big-files.patch— Fix lame code in fileio.c06-unzip-6.0-exec-shield.patch— adds an empty.note.GNU-stacksection tocrc_i386.S, so an object assembled from it asks for no executable stack. Theunzipstarget assembles that file only whenCRCA_Onames its object, andbuild.shdoes not set it.07-unzip-6.0-format-secure.patch— passes each messageInfo()prints through a"%s"format inextract.c,list.candzipinfo.c, instead of using the message itself as the format string.08-unzip-6.0-heap-overflow-infloop.patch— upstream fix for heap overflowhttps://bugzilla.redhat.com/attachment.cgi?id=1073002
09-unzip-6.0-timestamp.patch— Do not ignore extra fields containing Unix Timestamps10-CVE-2014-8139.patch— checks that a PKVMS extra-field block is at least four bytes long before computing its CRC, and reports a block that is too short (CVE-2014-8139).11-CVE-2014-8140.patch— intest_compr_eb(), treats a compressed extra field that declares an uncompressed size of zero as bad data (CVE-2014-8140).12-CVE-2014-8141.patch— makesgetZip64Data()inprocess.ccheck that enough bytes are left before reading each Zip64 field, and makes its caller infileio.cwarn that the extra field is corrupt when it fails (CVE-2014-8141).13-CVE-2014-9636.patch— Info-ZIP UnZip buffer overflowBy carefully crafting a corrupt ZIP archive with "extra fields" that purport to have compressed blocks larger than the corresponding uncompressed blocks in STORED no-compression mode, an attacker can trigger a heap overflow that can result in application crash or possibly have other unspecified impact.
This patch ensures that when extra fields use STORED mode, the "compressed" and uncompressed block sizes match.
14-CVE-2014-9913.patch— Fix CVE-2014-9913, buffer overflow in unzip15-CVE-2016-9844.patch— Fix CVE-2016-9844, buffer overflow in zipinfo16-CVE-2018-1000035.patch— sizes the buffer for the password prompt from the lengths of the two file names it prints, instead of a fixed2*FILNAMSIZ + 15bytes the names can overrun (CVE-2018-1000035).17-CVE-2018-18384.patch— widens the bufferlist_files()formats the compression factor into from 10 to 13 bytes (CVE-2018-18384).18-large-symlinks.patch— Re: "git archive" seems to be broken wrt zip filesJeff King <peff@peff.net> writes:
> IOW, the zip file looks right. I wonder if this is actually a bug in > "unzip".
It is. This only happens if you have more then 16k entries and when one of the 16k entry infos is reused it happend to be previously used for a symlink entry.
Here's a patch for unzip60 for reference:
19-CVE-2021-4217.patch— Fix null pointer dereference and use of uninitialized dataThis fixes a bug that causes use of uninitialized heap data if `readbuf` fails to read as many bytes as indicated by the extra field length attribute. Furthermore, this fixes a null pointer dereference if an archive contains an `EF_UNIPATH` extra field but does not have a filename set.
20-CVE-2022-0529-and-CVE-2022-0530.patch— Fix for CVE-2022-0529 and CVE-2022-053021-zipbomb-manpage.patch— update the man page22-zipbomb-part1.patch— Fix bug in undefer_input() that misplaced the input state.23-zipbomb-part2.patch— Detect and reject a zip bomb using overlapped entries.This detects an invalid zip file that has at least one entry that overlaps with another entry or with the central directory to the end of the file. A Fifield zip bomb uses overlapped local entries to vastly increase the potential inflation ratio. Such an invalid zip file is rejected.
See https://www.bamsoftware.com/hacks/zipbomb/ for David Fifield's analysis, construction, and examples of such zip bombs.
The detection maintains a list of covered spans of the zip files so far, where the central directory to the end of the file and any bytes preceding the first entry at zip file offset zero are considered covered initially. Then as each entry is decompressed or tested, it is considered covered. When a new entry is about to be processed, its initial offset is checked to see if it is contained by a covered span. If so, the zip file is rejected as invalid.
This commit depends on a preceding commit: "Fix bug in undefer_input() that misplaced the input state."
24-zipbomb-part3.patch— Do not raise a zip bomb alert for a misplaced central directory.There is a zip-like file in the Firefox distribution, omni.ja, which is a zip container with the central directory placed at the start of the file instead of after the local entries as required by the zip standard. This commit marks the actual location of the central directory, as well as the end of central directory records, as disallowed locations. This now permits such containers to not raise a zip bomb alert, where in fact there are no overlaps.
25-zipbomb-part4.patch— Fix bug in UZbunzip2() that incorrectly updated G.incnt.The update assumed a full buffer, which is not always full. This could result in a false overlapped element detection when a small bzip2-compressed file was unzipped. This commit remedies that.
26-zipbomb-part5.patch— Fix bug in UZinflate() that incorrectly updated G.incnt.The update assumed a full buffer, which is not always full. This could result in a false overlapped element detection when a small deflate-compressed file was unzipped using an old zlib. This commit remedies that.
27-zipbomb-part6.patch— Determine Zip64 status entry-by-entry instead of for entire file.Fixes a bug for zip files with mixed Zip64 and not Zip64 entries, which resulted in an incorrect data descriptor length. The bug is seen when a Zip64 entry precedes a non-Zip64 entry, in which case the data descriptor would have been assumed to be larger than it is, resulting in an incorrect bomb warning due to a perceived overlap with the next entry. This commit determines and saves the Zip64 status for each entry based on the central directory, and then computes the length of each data descriptor accordingly.
28-zipbomb-part7.patch— Be more liberal in the acceptance of data descriptors.Previously the zip64 flag determined the size of the lengths in the data descriptor. This is compliant with the zip format. However, a bug in the Java zip library results in an incorrect setting of that flag. This commit permits either 32-bit or 64-bit lengths, auto- detecting which it is, which works around the Java bug.
29-zipbomb-switch.patch— Add an option to disable the zipbomb detectionThis can be done by settting a newly introduced environment variable UNZIP_DISABLE_ZIPBOMB_DETECTION to {TRUE,True,true}. If the variable is unset, or set to any other value the zipbomb detection is left enabled.
Example: UNZIP_DISABLE_ZIPBOMB_DETECTION=True unzip ./zbsm.zip -d ./test
30-gcc15.patch— declaresgmtime()andlocaltime()inunix/unxcfg.hwith theirconst time_t *parameter, the prototype<time.h>gives them, instead of with an empty parameter list. That declaration is on the branch of#ifdef BSDthat this build’s-DBSDdoes not take.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install unzip'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/archiver/unzip.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/archiver/unzip
echo '036d96991646d0449ed0aa952e4fbe21b476ce994abc276e49d30e686708bd37 unzip-6.0.tar.gz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/unzip
SRC=$SRC_ROOT/unzip-6.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf unzip-6.0.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the recipe’s helpers _version and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
for p in "$PORT_SRC"/[0-9][0-9]-*.patch; do
patch -p1 -i "$p"
done
make -f unix/Makefile unzips CC="$CC" LD="$CC" \
CFLAGS="$CFLAGS" LF2="$LDFLAGS" \
D_USE_BZ2=-DUSE_BZIP2 L_BZ2=-lbz2 \
LOCAL_UNZIP="-DBSD -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DLARGE_FILE_SUPPORT -DUNICODE_SUPPORT -DUNICODE_WCHAR -DUTF8_MAYBE_NATIVE -include time.h" \
prefix=$PKG/usr
make prefix=$PKG/usr MANDIR=$PKG/usr/share/man/man1 -f unix/Makefile install
The switches, and why each is set:
unzips— the make target: buildunzip,funzipandunzipsfxwith the flags given on the command line, and never rununix/configure. Nothing is detected, so every feature the build has is one of the definitions below.CFLAGS="$CFLAGS"— the tree’s flags, in place of the makefile’s own-O.LF2="$LDFLAGS"— the tree’s linker flags, in place of the makefile’s-s, which would strip the programs at link time.LD="$CC"— link with the compiler. The makefile requiresCCandLDto be the same program.D_USE_BZ2=-DUSE_BZIP2— withL_BZ2=-lbz2: support the bzip2 compression method, linked against the bzip2 port’s library. Both are commented out in the makefile, whose comment says they must be set to turn bzip2 support on.LOCAL_UNZIP— the definitions added to every compile line.-DLARGE_FILE_SUPPORTturns on 64-bit file offsets and, with them,ZIP64_SUPPORT, so archives and members over 4 GB open.-DUNICODE_SUPPORT,-DUNICODE_WCHARand-DUTF8_MAYBE_NATIVEread the UTF-8 names an archive records and write them as UTF-8, so a non-ASCII name is not mangled.-DBSDselects UnZip’s own BSD code paths; on that pathunix/unxcfg.hincludes<sys/time.h>and<sys/timeb.h>and adds<time.h>only for glibc, so-include time.hputs<time.h>ahead of every source file for musl.-D_BSD_SOURCEand-D_DEFAULT_SOURCEselect the BSD and default interfaces of the C library, and-D_LARGEFILE64_SOURCEand-D_FILE_OFFSET_BITS=64restate the 64-bit interface musl always has.prefix=$PKG/usr— withMANDIR=$PKG/usr/share/man/man1: wheremake installwrites. The makefile takes noDESTDIR, so the staging directory goes into the prefix, and its manual directory is otherwise$(prefix)/man/man1.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/unzip, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf unzip-6.0-2.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/unzip, and runs the triggers its paths call for.
Contents
Installed programs: funzip, unzip, unzipsfx, zipgrep, zipinfo.
Installed directories: /usr/share/licenses/unzip.
Short descriptions
funzip |
filter for extracting from a ZIP archive in a pipe |
unzip |
list, test and extract compressed files in a ZIP archive |
unzipsfx |
self-extracting stub for prepending to ZIP archives |
zipgrep |
search files in a ZIP archive for lines matching a pattern |
zipinfo |
list detailed information about a ZIP archive |
Notes
29-zipbomb-switch.patch makes the zip-bomb check switchable: with UNZIP_DISABLE_ZIPBOMB_DETECTION=TRUE in the environment, unzip extracts an archive with overlapping entries instead of refusing it.