713 Commits
Author SHA1 Message Date
Tobias Stoeckmann 37b0b5a502 unzip: Add Windows port
Copy missing functionality from libarchive and cpio.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-24 18:02:15 +02:00
Dustin L. Howett 02447e94d0 iso9660: add a test for the 32-bit zisofs overflow case
Writing a file near 4 GiB causes an overflow when we calculate the
number of block pointers we need to store, which leads to us allocating
the wrong amount of memory to store them.

This is visible with ASan:

Exercising: libarchive 3.9.0dev zlib/1.3.1 liblzma/5.4.4 bz2lib/1.0.8 libzstd/1.5.6 cng/2.0 libb2/bundled
706: test_write_format_iso9660_zisofs_overflow
=================================================================
==40444==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x08c004b4 at pc 0x006acb3b bp 0x002edb44 sp 0x002edb38
WRITE of size 1 at 0x08c004b4 thread T0
    #0 0x006acb3a in archive_le32enc libarchive\archive_endian.h:219
    #1 0x006c81d0 in zisofs_write_to_temp libarchive\archive_write_set_format_iso9660.c:7760
    #2 0x006ca1bd in write_iso9660_data libarchive\archive_write_set_format_iso9660.c:1785
2026-06-24 10:51:48 -05:00
Dustin L. Howett 6b468d68d1 Merge pull request #3160 from GeorgH93/fix_zipx_streaming_non_seekable
Fix zipx reading with ZIP_LENGTH_AT_END flag from non-seekable source
2026-06-24 08:42:37 -05:00
Tim Kientzle 6f85565e42 Merge pull request #3175 from uchiha-bug-hunter/xar-base64-oob-read
xar: fix OOB read decoding odd-length base64 in strappend_base64
2026-06-24 06:10:15 -07:00
Kaif Khan 79fe496410 unzip: add regression test for insecure '..' symlink targets 2026-06-24 12:00:05 +05:30
Kaif Khan 98c25d8b5c xar: add regression test for odd-length base64 name decoding
Crafted TOC with a base64-encoded <name> of odd length, which used to
make strappend_base64() read past the character-data buffer. The trailing
incomplete base64 character is dropped; the rest still decodes.
2026-06-24 10:56:44 +05:30
Dustin L. Howett c0e779b73c Merge pull request #3162 from soda0289/add-windows-long-path-manifest
tar: mark bsdtar as long-path aware on Windows

tar -C/--directory option calls SetCurrentDirectoryW(), which is limited to MAX_PATH (260) characters unless the process opts in to longpath support via an application manifest and enables a registry setting or sets an option in developer settings.
2026-06-23 23:33:12 -05:00
Tobias Stoeckmann 34b3da0013 unzip: Add symlink tests
Verify that symlink creations and overwriting works, i.e. that dangling
symlinks are properly overwritten.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-23 20:12:26 +02:00
Tobias Stoeckmann a3d38d0272 unzip: Add -u test
Verify that -u does not override files which have a newer timestamp.

This also verifies that creation of timestamps properly works.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-23 20:12:26 +02:00
Tobias Stoeckmann 4f70bf0e7b unzip: Add -f test
Verify that -f does not create new files and also does not override
files which have a newer timestamp.

This also verifies that creation of timestamps properly works.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-23 20:12:23 +02:00
Reyad Attiyat 6ef83d7a41 tar: mark bsdtar as long-path aware on Windows
bsdtar's -C/--directory option calls SetCurrentDirectoryW(), which is
 limited to MAX_PATH (260) characters unless the process opts in to long
 path support via an application manifest declaring longPathAware.
 Extracting into (or changing into) a directory whose path exceeds 260
 characters fails with "could not chdir".

 Embed a longPathAware application manifest into bsdtar.exe so these
 operations work for long destination paths. Both Windows build systems
 (CMake and the autotools/Makefile.am build) embed it, using different
 mechanisms per toolchain:

   - MinGW/Clang (GNU ld) do not generate an application manifest, so it
     is compiled from a resource script (bsdtar.rc) via windres. This
     manifest replaces the toolchain default, so it also declares the
     asInvoker execution level explicitly.
   - MSVC's linker already embeds a manifest (resource id 1); a duplicate
     RT_MANIFEST resource fails to link (CVT1100). Instead the manifest is
     merged into the linker's default manifest (asInvoker) by adding it to
     the target sources.
2026-06-22 22:37:05 -05:00
Tobias Stoeckmann 2615ba5cd5 libarchive_fe: Import FreeBSD's fnmatch
If system lacks fnmatch(3), use FreeBSD's fnmatch. It's adjusted for
increased compatibility, i.e. it uses strcoll instead of FreeBSD's
library internals and const char pointers where needed with latest
GNU/Linux toolchains.

FreeBSD source can be obtained here:

https://github.com/freebsd/freebsd-src/blob/dc36d6f9bb1753f3808552f3afd30eda9a7b206a/lib/libc/gen/fnmatch.c

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-22 20:32:23 +02:00
Dustin L. Howett 7ab1a6538e Merge commit from fork
xattr/sparse: Fix UAF by nullifying pointer
2026-06-18 11:41:47 -05:00
GeorgH93 22d16a04e4 Fix reading ppmd8 zipx with ZIP_LENGTH_AT_END flag from non-seekable stream 2026-06-17 22:42:50 +02:00
Martin Matuška f6dea9e94b Merge pull request #3134 from stoeckmann/archive_integer
Introduce `archive_integer.h` for checked arithmetic
2026-06-17 08:48:55 +02:00
Dustin L. Howett 5e566cf0c6 Merge pull request #3153 from stoeckmann/cab_multi
cab: Fix multi volume parser
2026-06-16 21:57:14 -05:00
Tobias Stoeckmann 551623e6ed cab: Add test for multi volume archives
The cab reader does not support multi volume archives, but it should be
able to read the files to print information about content.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-16 21:37:55 +02:00
Tobias Stoeckmann 16be338523 Add archive_integer.h
The archive_integer.h header offers various integer operations to
libarchive, utilizing system functionality where possible.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-12 23:32:36 +02:00
Dustin L. Howett b66d136b70 Merge pull request #2865 from GeorgH93/read_zipx_encryption
Add support for reading encrypted zipx formats (bzip2, lzma, ppmd, xz, zstd)
2026-06-12 10:28:45 -05:00
GeorgH93 b266da129a Introduce zipx encryption handling for zstd compressed zip files 2026-06-12 12:02:41 +02:00
GeorgH93 43682f0e7a Introduce zipx encryption handling for bzip2 compressed zip files 2026-06-12 12:02:41 +02:00
GeorgH93 26256df5ab Introduce zipx encryption handling for lzma compressed zip files 2026-06-12 12:02:33 +02:00
GeorgH93 91ffcda239 Introduce zipx encryption handling for xz compressed zip files 2026-06-12 12:01:15 +02:00
GeorgH93 02411983a5 Introduce zipx encryption handling for ppmd compressed zip files 2026-06-12 12:01:09 +02:00
GeorgH93 67a848c947 Add test for creating encrypted zip file with libarchive and reading it again with libarchive 2026-06-12 11:54:14 +02:00
Tobias Stoeckmann 10bd4da47b Merge pull request #2923 from bililateral/pr-7zip-numfiles-oom
7zip: sanity-check FilesInfo NumFiles before allocating entries
2026-06-12 08:27:25 +02:00
Dustin L. Howett c09f7b044b Merge pull request #3105 from i1011/rar-unbounded-staticdata-fix
rar: Add missing bound check for staticdata
2026-06-11 23:09:19 -05:00
bililateral 57389860f5 7zip: sanity-check FilesInfo NumFiles before allocating entries 2026-06-10 10:07:01 +08:00
Dustin L. Howett bede9a3692 Merge pull request #3048 from legnaleurc/fix/rar-reset-lz-table
rar: reset low-distance state for new LZ tables
2026-06-09 20:30:47 -05:00
Dustin L. Howett 82404ac239 Merge pull request #3047 from legnaleurc/fix/rar-recovery-record
rar: skip NEWSUB payloads without size cap
2026-06-09 20:26:31 -05:00
datauwu 1960646fe8 7zip: add malformed SubStreamsInfo test
Add a 7z regression test for malformed SubStreamsInfo metadata that
declares more than one unpack stream without the kSize data needed to
describe those streams.

Store the archive as a .7z.uu file, matching the existing malformed
7z tests.
2026-06-10 03:10:27 +08:00
Martin Matuška d9279e464c Merge pull request #3121 from stoeckmann/rar5_bytes_remaining
rar5: fix signed integer underflow in bytes_remaining
2026-06-09 08:30:03 +02:00
Dustin L. Howett e501d52c74 Merge pull request #3021 from chnzzh/fix/iso9660-ce-loop
iso9660: fix infinite loop on self-referencing CE entry
2026-06-08 19:06:43 -05:00
00redbeer 7e056baa5c rar5: check integer overflow in bytes_remaining
A malformed RAR5 archive with data_size=1 forces bytes_remaining
(ssize_t) to wrap to -2 when a compressed block header consumes
to_skip=3 bytes (CWE-191). That negative value is then implicitly
cast to size_t ~0 inside malloc(), requesting a ~16-exabyte
allocation — confirmed heap buffer overflow via ASAN/UBSan on a
48-byte crafted archive requiring no authentication.

Reproducer: 48-byte crafted RAR5 archive; ASAN confirms
"allocation-size-too-big 0xfffffffffffffffe".

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 15:06:59 +02:00
i1011 cc5b027ee5 rar: Add test of large staticdatalen in header 2026-06-03 01:29:49 +08:00
Martin Matuška 6ac02f9521 Merge pull request #3073 from stoeckmann/lz4_zstd_32
lz4/zstd: Fix 32 bit platform endless loop and OOB access during bidding
2026-06-02 15:05:42 +02:00
Martin Matuška 9b5c25087e Merge pull request #3091 from yPin9/fix/rar5-consume-remaining
rar5: skip unconsumed block bytes before ARCHIVE_RETRY
2026-06-02 15:04:44 +02:00
Martin Matuška 66026841b2 Merge pull request #3093 from stoeckmann/lz4_skip
lz4: Improve truncated input stream detection
2026-06-01 09:55:02 +02:00
Tobias Stoeckmann 298facb31e cpio: Add afio header split test
Verify that afio headers are detected even on unfortunate filter read
splits, i.e. when magic is found but rest of header has yet to be
retrieved.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-30 21:58:51 +02:00
yPin9andClaude Opus 4.8 3b466c2456 rar5: consume unconsumed block bytes before ARCHIVE_RETRY
process_base_block() returned ARCHIVE_RETRY for HEAD_MAIN (and
HFL_SKIP_IF_UNKNOWN) blocks without consuming the body bytes the
sub-parser did not read. rar5_read_header() then re-parsed the same
region, turning an O(1) skip into O(N) and letting a crafted RAR5 file
stall the reader (GHSA-9h2c-464f-j3hj).

Record the block body start and skip any unconsumed bytes through a
small helper rar5_skip_remaining_block() before returning ARCHIVE_RETRY.

Add two regression tests derived from test_read_format_rar5_stored, each
with extra unread bytes appended to a no-data block's body (HEAD_MAIN and
an unknown HFL_SKIP_IF_UNKNOWN block); both fail on master and pass with
the fix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-30 20:19:25 +08:00
Tobias Stoeckmann 303482693a lz4: Add check for proper byte skipping
Check if truncated input is detected while skipping data.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-29 18:02:04 +02:00
Tobias Stoeckmann f105880eb0 iso9660: Add Rock Ridge regression test
The Rock Ridge rr_move functionality for paths with a depth larger than 8
has a few bugs in it. For one, it might loop over the same entries over
and over. And second, rr_move/ directory entries are not verified to be
unique. Both issues can lead to NULL pointer dereferences.

Add a test case which highlights the NULL pointer dereference.

Based on issue #2936.
2026-05-26 21:01:38 +02:00
Tobias Stoeckmann f948099a0d zstd: Check for endless loop on 32 bit systems
It is possible to trigger an endless loop on 32 bit systems due to
a triggerable integer overflow.

Add a regression test for this.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-25 22:11:12 +02:00
Tobias Stoeckmann 51e9cd6dc7 Merge pull request #3052 from stoeckmann/tar_wempty
tar: Fix OOB with empty wide character directory names
2026-05-24 10:14:50 +02:00
Tobias Stoeckmann e681e45b31 Merge pull request #3041 from stoeckmann/xar_fflags
xar: Fix writer OOB accesses with fflags
2026-05-24 10:13:34 +02:00
i1011 e21749afe3 Add test for filter dispatch in archive_write_add_filter.c
Modified from test_archive_write_add_filter_by_name.c
2026-05-20 20:56:40 +08:00
Tobias Stoeckmann e04cc903e0 tar: Check empty dir name handling
Make sure that empty wide character names do not lead to out of boundary
accesses.

Reported by shura-turtle.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-19 21:18:22 +02:00
Wei-Cheng Pan b1a5aa97a3 rar: reset low-distance state for new LZ tables
Low-distance repeat state is scoped to the current RAR3 LZ table. Reusing it after a new table starts can make the next match use the wrong offset, producing incorrect output and a file CRC error.

Reset lastlowoffset and numlowoffsetrepeats when parsing a new LZ table. Add a small handcrafted RAR3 fixture that leaves a low-distance repeat pending, switches tables, and verifies the decoded bytes after the boundary.
2026-05-19 17:16:53 +09:00
Wei-Cheng Pan e09d88eaa3 rar: skip NEWSUB payloads without size cap
RAR3 recovery records can be stored as NEWSUB RR blocks with payloads larger than the old 1 MiB extended-header limit. These records are metadata-only for this reader, so after validating the header and guarding against header-size plus payload-size overflow, consume the remaining header bytes and payload instead of rejecting the archive.

Add a reference archive with a NEWSUB RR payload just over 1 MiB, and keep the malformed huge-size case covering the overflow/truncation path.
2026-05-19 17:14:12 +09:00
Tobias Stoeckmann 68b69249de Merge commit from fork
read: Fix memory corruption on filtered multi-volume archives
2026-05-17 10:21:08 +02:00