8131 Commits
Author SHA1 Message Date
Dustin L. Howett 4767d73519 Merge pull request #3239 from datauwu/warc-require-size 2026-07-04 14:24:22 -05:00
datauwu 3a2538bca3 warc: require file size before writing header
WARC records require a known Content-Length. Reject regular file
entries without a valid size instead of treating them as zero.
Avoid casting archive_entry_size() through size_t before storing it in
the uint64_t WARC Content-Length field, since that can truncate large
sizes on 32-bit platforms.
2026-07-05 03:11:15 +08:00
Tim Kientzle f66b4c7f8f Merge pull request #3238 from stoeckmann/cpio_ioflow
cpio: Prevent signed integer overflow
2026-07-04 10:43:37 -07:00
datauwu 366baca718 warc: test missing file size handling
Add coverage for WARC entries without a known size. The writer
must reject these entries because WARC requires Content-Length.
2026-07-05 01:26:57 +08:00
Tobias Stoeckmann c1ce208f8e cpio: Prevent signed integer overflow
If enough bytes have to be skipped, a signed integer overflow could
occur (most realistically on 32 bit systems). Use an unsigned type,
which could still overflow but has only negative impact on diagnostic
warning message.

Follow up of 02fa05675f but this time for
function find_newc_header.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-04 19:06:52 +02:00
Tim KientzleandTobias Stoeckmann 1ff24fb981 Update libarchive/archive_read_data_into_fd.c
Co-authored-by: Tobias Stoeckmann <stoeckmann@users.noreply.github.com>
2026-07-04 09:48:31 -07:00
Tobias Stoeckmann 41a72e5553 Merge pull request #3231 from datauwu/7zip-skip-archiveproperties
7zip: skip ArchiveProperties payload data
2026-07-04 09:56:23 +02:00
datauwu 9c5210e8a5 pax: remove redundant hardlink size assignment
archive_write_pax_header() set hardlink entries to size zero for the
restricted pax format, then immediately set all hardlink entries to size
zero again.

Remove the narrower check because it is fully subsumed by the following
hardlink check.

No functional change intended.
2026-07-04 13:57:33 +08:00
datauwu 426f2aef86 tar: avoid parsing mode field twice
header_common() parsed the tar mode field once when setting the file
type and again when setting permissions. Cache the parsed value and reuse
it for both setters.

archive_entry_set_filetype() and archive_entry_set_perm() already mask
the relevant bits, so passing the full header mode preserves behavior.
The permission-set guard is unchanged.

No functional change intended.
2026-07-04 13:57:32 +08:00
Tim Kientzle d2a224f443 Fix the test failure
This was originally developed without the Zip fix from #3230.
Since that's been merged, we need to adjust the expectations here
a bit.
2026-07-03 21:52:27 -07:00
Tim Kientzle ec36bf4179 Rework size-overrun check to avoid arithmetic errors 2026-07-03 21:41:08 -07:00
Tim Kientzle aba955e416 [Write] Truncate write-to-fd at the declared entry size
This is	the fix for....

Update the common archive_read_data_into_fd() to truncate
output to the actual entry size	from the most recent
archive_read_header result.

This addresses a hole in handling of certain subtly-malformed archives
that can have more data than declared in the header.  Before this,
bsdtar explicitly truncates the entry data to the actual declared size
when extracting to a file, but did not do so when extracting to
stdout.
2026-07-03 21:41:08 -07:00
Tim Kientzle e7e408a1a9 [Write] Truncate write-to-fd at the declared entry size
This is the test for....

Update the common archive_read_data_into_fd() to truncate
output to the actual entry size from the most recent
archive_read_header result.

This addresses a hole in handling of certain subtly-malformed archives
that can have more data than declared in the header.  Before this,
bsdtar explicitly truncates the entry data to the actual declared size
when extracting to a file, but did not do so when extracting to
stdout.
2026-07-03 21:41:08 -07:00
Tim Kientzle ba542208a3 [Zip] Reject archives if the 32-bit size field is not correct
Reverse an old experiment: When the 32-bit size field is provided, it
now must match the actual size exactly.  We no longer permit it to
only match the least-significant 32 bits of the actual size.

--begin-history--
When developing the earliest versions of libarchive's Zip support, I
experimented with the idea of supporting greater-than-4GiB entries in
32-bit Zip archives.  This proved to be technically feasible as long
as the _compressed_ data was small enough to keep the resulting
archive under 4GiB.  But this also required us to interpret
the 32-bit uncompressed size field as representing only the
least-significant 32 bits of the size.
--end-history--
2026-07-03 21:25:54 -07:00
Tim Kientzle 1559ae86da [Zip] Be strict about the 32-bit uncompressed size
Test:  If the uncompressed size stored in the archive differs
from the actual uncompressed size by a multiple of 2^32,
we should report some kind of error.

This currently goes undiagnosed because of an old attempt
to support larger-than-4GiB entries in plain 32-bit Zip
archives without necessarily requiring Zip64 extensions.
While this is technically feasible, it requires treating
the 32-bit size field ambiguously, which can lead to size
confusion from readers.
2026-07-03 21:22:48 -07:00
datauwu fbad49b708 7zip: skip ArchiveProperties payload data
ArchiveProperties entries have a property ID, a size, and payload.

The reader parsed the ID and size, but did not consume the payload.
Payload bytes could then be read as the next property ID, which
misaligned the rest of header parsing.

Skip the payload in chunks so parsing stays aligned with 7-Zip/7zz.
2026-07-04 12:00:07 +08:00
Tobias Stoeckmann f4493cea76 raw: Properly treat huge inputs
If the raw parser ever treats a basically endless stream which
eventually overflows INT64_MAX, fail instead of overflowing
offset + size calculation, leading to subsequent issues in callers.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-03 23:26:28 +02:00
Tobias Stoeckmann 47964b3533 Check archive_entry_new2 return value
The memory allocation might fail. Check return value and properly handle
error cases.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-03 22:45:11 +02:00
Tim Kientzle 5a2ec45b9c Merge pull request #3230 from kientzle/kientzle-zip-reject-overlong-bodies
[Zip] Reject entries with overlong bodies
2026-07-03 13:26:30 -07:00
Tim Kientzle c11df428d1 [Zip] Reject entries with overlong bodies
If an entry declares an uncompressed size, we should not return any
data beyond that point.  This doesn't impact bsdtar and friends since
they independently truncate to the declared entry size, but other
clients may not be so careful.

Apparently discovered (but not reported) by @bikini
Reported by @dkgkdfg65
2026-07-03 13:14:27 -07:00
Tim Kientzle 5f29836190 [Zip] Reject entries with overlong bodies
Tests for...

If an entry declares an uncompressed size, we should not return any
data beyond that point.  This doesn't impact bsdtar and friends since
they independently truncate to the declared entry size, but other
clients may not be so careful.

Apparently discovered (but not reported) by @bikini
Reported by @dkgkdfg65
2026-07-03 13:13:31 -07:00
Dustin L. Howett 5933c80ae5 Merge pull request #3229 from stoeckmann/cab_e8 2026-07-03 13:38:20 -05:00
datauwu 49a273e314 7zip: add ArchiveProperties payload test
Add a 7z test archive with a non-empty ArchiveProperties payload.

The archive has one empty file and an ArchiveProperties entry with a
1-byte payload. It is accepted by 7-Zip/7zz.

This covers parsing when ArchiveProperties has payload bytes.
2026-07-04 01:44:58 +08:00
Tim Kientzle 47999c275f Merge pull request #3228 from datauwu/zip-encrypted-int-overflow
zip: avoid signed overflow in encrypted size checks
2026-07-03 09:36:45 -07:00
datauwu 1c6e7b491f zip: avoid signed overflow in encrypted size checks
Avoid adding the encryption overhead directly to entry sizes when deciding
whether Zip64 is needed or when updating the stored compressed size.

For the Zip64 decision, compare against ZIP_4GB_MAX - additional_size. For
stored encrypted entries, use archive_ckd_add_i64() so the size update and
overflow check happen together.
2026-07-03 23:48:50 +08:00
Tobias Stoeckmann 53d1c0bc65 cab: Add E8 translation test
Covers basic E8 translations, yet it lacks the handling of negative
values because this would require large archives.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-03 17:37:37 +02:00
Tobias Stoeckmann 220eefe346 cab: Translate E8 calls only in first 1 GB of data
The cab specification states that E8 translation shall be performed only
within the first 1 GB range of an uncompressed file, i.e. for the first
0x8000 CFDATA entries in a folder.

Take this limit properly into account.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-03 17:37:34 +02:00
Dustin L. Howett 42b2444920 Merge pull request #3208 from datauwu/7zip-skip-defined-bitmaps 2026-07-02 20:22:52 -05:00
datauwu a32e870da4 7zip: skip fully-defined metadata bitmaps
Avoid allocating and filling metadata bitmaps when the 7z header says
that every file has the corresponding value.

Sparse metadata still uses the existing bitmap path.
2026-07-03 08:24:15 +08:00
Dustin L. Howett 1162aaeccb Merge pull request #3224 from datauwu/formats-remove-unused-state
formats: remove unused states from 7 formats
2026-07-02 17:27:28 -05:00
Dustin L. Howett 6c97b0ae54 Merge pull request #3226 from uchiha-bug-hunter/pathmatch-wide-bracket-overread
pathmatch: fix wide-char bracket over-read in pm_w
2026-07-02 14:40:59 -05:00
Dustin L. Howett e3f9ed95b7 win32: repair symlink mode 'H' (hybrid) in wildcard search
The Windows disk reader supports wildcards by converting a path like
"foo/*" into a single tree rooted at "foo/". This does not play nicely
with symlink mode `H`, which treats the first item in each tree as a
dereferenced link (L) and all subsequent items as physical links (P). On
Windows, we take the first _match_ in L mode and all subsequent
descendants and matches in P mode.

This creates a behavioral difference between `bsdtar -c -H *` and
`bsdtar -c -H one two three`.

This commit changes how we handle H->L/P transitions when doing wildcard
matches. The transition from H to P is now done when we descend into our
first directory, and we switch back to H mode when we ascend out of
it[^1].

Closes #3222

[^1]: This does not matter in practice because tree is breadth-first
rather than depth-first, but I've done it in the interest of
completeness and not leaving ourselves caltrops to step on later.
2026-07-02 14:26:40 -05:00
Kaif Khan 262461917e pathmatch: guard end-of-string before wide bracket class match 2026-07-02 22:36:44 +05:30
Kaif Khan 10ca288a48 test: cover wide bracket over-read in pm_w 2026-07-02 22:36:44 +05:30
datauwu e42a14d5e7 write: remove unused zip and warc fields
Remove writer fields that are initialized but never read.
2026-07-02 21:44:48 +08:00
datauwu 1a98844466 rar5: remove unused filter_info fields
Remove filter_info fields that are never assigned or read.
2026-07-02 21:44:48 +08:00
datauwu c5f1dba4e3 rar: remove unused globalbackup fields
Remove RAR filter backup fields that are never used.
2026-07-02 21:44:48 +08:00
datauwu f12b3fe00c cab: remove unused LZX tree_used state
Remove LZX Huffman state that is reset but never read.
2026-07-02 21:44:48 +08:00
datauwu ebe53f5fcd cab: remove unused header and entry fields
Remove CAB fields that are parsed or reset but never read.
2026-07-02 21:44:48 +08:00
datauwu 4f9f341f16 zip: remove unused central directory counters
Remove counters that are initialized or incremented but never read.
2026-07-02 21:40:07 +08:00
Dustin L. Howett 0c856d3a8f Merge pull request #3206 from DHowett/win32-symlink-bypass 2026-07-02 07:25:37 -05:00
Dustin L. Howett e707414ed8 win32: prevent writing through a broken symlink in insecure mode
The comments document that we were expecting O_EXCL behavior, and
archive_write_disk_posix uses O_EXCL as well. Let's use O_EXCL's nearest
equivalent.
2026-07-01 21:43:09 -05:00
Dustin L. Howett 52bf591c1a Merge pull request #3221 from stoeckmann/callback_data_check 2026-07-01 16:04:34 -05:00
Tobias Stoeckmann dfcc108ebd Check result of archive_read_set_callback_data
The memory allocation in archive_read_set_callback_data2, which is
called by archive_read_set_callback_data, could fail.

Check result and properly handle failure.

Resolves #3210.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-01 22:38:58 +02:00
Dustin L. Howett 983f8da4be Merge pull request #3216 from setarcos/loongarch
test: fix incorrect hole count reporting on loongarch64
2026-07-01 12:03:18 -05:00
Dustin L. Howett 0b661a91be Merge pull request #3217 from datauwu/7zip-simplify-bool-handling
7zip: simplify bool handling
2026-07-01 12:02:12 -05:00
Dustin L. Howett d586479a72 Merge pull request #3218 from datauwu/7zip-redundant-bcj-assign
7zip: drop redundant BCJ2 assignments
2026-07-01 12:01:06 -05:00
datauwu 5cd808a44b 7zip: simplify metadata bool handling
Flatten nested allAreDefined checks for attribute and timestamp bools.

Also initialize empty-stream entries as directories by default before
applying the optional EmptyFile bitmap.

No archive behavior change is intended.
2026-07-01 23:10:46 +08:00
datauwu 86fd6c20c0 7zip: drop redundant BCJ2 assignments
Both supported BCJ2 layout branches store the chosen unpack size in
remaining.

main_stream_bytes_remaining is set from remaining immediately after
the branch, so the earlier assignments are redundant.
2026-07-01 22:56:30 +08:00
Pluto Yang 22af22edb8 test: fix incorrect hole count reporting on loongarch64
On LoongArch64 with 16KB pages, Linux tmpfs often uses Transparent
Huge Pages (THP) sized at 32MiB. When a test writes data followed
by a 32MiB hole, the kernel may allocate a single huge page folio
to back the entire range in RAM. Because the range is physically
backed by memory, SEEK_HOLE correctly (from the kernel's perspective)
identifies the range as DATA, failing the test's assertion. Increasing
MIN_HOLE to 64MiB ensures the hole exceeds the huge page size on
loongarch64, preserving the sparse nature of the file for the test.

Signed-off-by: Pluto Yang <yangyj.ee@gmail.com>
2026-07-01 22:17:08 +08:00