Commit Graph
93 Commits
Author SHA1 Message Date
Tobias Stoeckmann 0b42deee05 Merge pull request #3348 from stoeckmann/signature_len
program: Avoid signature length overflow
2026-08-08 17:54:31 +02:00
Tobias Stoeckmann da33bf2d71 Merge pull request #3279 from datauwu/warc-modernize-comments
warc: modernize comments
2026-07-11 12:01:19 +02:00
Tobias Stoeckmann ba202cdafc Merge pull request #3259 from uchiha-bug-hunter/7zip-bound-header-counts
7zip: bound folder and stream counts before allocating
2026-07-09 08:34:32 +02:00
Tobias Stoeckmann 761652401f Merge pull request #3220 from DHowett/fix-assertions-lstat
test: make Windows file assertions act like lstat
2026-07-07 19:28:21 +02: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
Tobias Stoeckmann ab4f2a57e9 Merge pull request #3205 from DHowett/assert-mem-obo
Fix two more off-by-ones calling assertEqualMem
2026-06-29 22:11:18 +02:00
Tobias Stoeckmann b1677ddb92 Merge pull request #3185 from stoeckmann/7zip_integers
7zip: Improve integer handling
2026-06-27 16:57:10 +02:00
Tobias Stoeckmann 4558c310de Merge pull request #3167 from stoeckmann/unzip_windows
unzip: Add Windows port
2026-06-27 16:56:53 +02:00
Tobias Stoeckmann df13c97c45 Merge pull request #3176 from stoeckmann/unzip_tests
unzip: Extend test suite
2026-06-23 20:29:22 +02:00
Tobias Stoeckmann c56456886d Merge pull request #3166 from stoeckmann/unzip_p_enc_test
unzip: Skip another test if zlib unavailable
2026-06-22 07:44:58 +02:00
Tobias Stoeckmann 042501f89c Merge pull request #3158 from stoeckmann/cpio_write
cpio: Fix writer OOB read with very long filenames
2026-06-18 22:51:43 +02:00
Tobias Stoeckmann 8510878d38 Merge pull request #3145 from stoeckmann/cab_max_namelen
cab: Properly limit maximum name length
2026-06-17 08:32:03 +02:00
Tobias Stoeckmann 42c656a3f9 Merge pull request #3140 from DHowett/dh/write-free-1
test: remove one new instance of assertEqualIntA(...free...)
2026-06-12 18:05:13 +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
Tobias Stoeckmann 9bd1a06adb Merge commit from fork
unzip: reject absolute or traversing symlink targets
2026-06-11 17:41:31 +02:00
Tobias Stoeckmann f1b6650c67 Merge pull request #3081 from stoeckmann/tests_i686_asan
tests: Skip checks on low memory systems
2026-06-02 08:12:43 +02:00
Tobias Stoeckmann 1e0736a92e Merge pull request #3104 from stoeckmann/uu_cleanup
uu: Minor code cleanups
2026-06-02 08:12:22 +02:00
Tobias Stoeckmann 3b6b10e7e2 Merge pull request #3085 from stoeckmann/gzip_check
gzip: Support more large in-memory archives
2026-05-29 18:00:49 +02:00
Tobias Stoeckmann d5053c3512 Merge pull request #3083 from stoeckmann/read_int_overflow
Fix integer overflow in __archive_read_filter_ahead
2026-05-28 22:46:43 +02:00
Tobias Stoeckmann e1efb9a7eb Merge pull request #3084 from stoeckmann/filters_total_out
Drop total_out tracking from read filters
2026-05-28 22:46:23 +02:00
Tobias Stoeckmann d6654b4e01 Merge pull request #3080 from stoeckmann/tests_skip
tests: Fix memory leaks when skipping
2026-05-27 22:01:10 +02:00
Tobias Stoeckmann cd61f4cc59 Merge pull request #3077 from stoeckmann/32build
32 bit: Fix compile warnings and test failure
2026-05-26 22:06:54 +02:00
Tobias Stoeckmann a662e108f2 Merge pull request #2972 from stoeckmann/rr_moved
iso9660: Add test for #2978
2026-05-26 21:14:32 +02:00
Tobias Stoeckmann 8b56378deb Merge pull request #3050 from stoeckmann/bzip2_large
bzip2: Support large in-memory archives
2026-05-26 20:00:19 +02:00
Tobias Stoeckmann 5c8a084f9d Merge pull request #3072 from stoeckmann/tests_free
tests: Avoid assertEqualIntA with archive_*_free
2026-05-26 19:59:56 +02:00
Tobias Stoeckmann 531d70f88c Merge pull request #3074 from stoeckmann/7zip_stream
7zip: Support streamable reading again
2026-05-26 19:59:38 +02:00
Tobias Stoeckmann e20a0b2136 Merge pull request #3051 from stoeckmann/compress_debug
compress: Remove harmful "dead" code
2026-05-24 10:15:35 +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 97595197b2 Merge pull request #3035 from stoeckmann/acl_string
acl: Simplify string creation
2026-05-24 10:14:11 +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
Tobias Stoeckmann fd182c5ba5 Merge pull request #3027 from stoeckmann/xar_debug
xar: Do not modify variables in DEBUG block
2026-05-19 17:19:06 +02:00
Tobias Stoeckmann 0637bc4221 Merge pull request #3033 from stoeckmann/filter_strcpy
filter: Remove unneeded strcpy calls
2026-05-19 17:18:05 +02:00
Tobias Stoeckmann 14c07f64ae Merge pull request #3036 from stoeckmann/cmdline_strdup
cmdline: Use free+strdup instead of realloc+strcpy
2026-05-19 17:17:42 +02:00
Tobias Stoeckmann ccd2dfbdb2 Merge pull request #3037 from stoeckmann/strmode_strcpy
strmode: Remove strcpy usage
2026-05-19 17:17:24 +02:00
Tobias Stoeckmann b9eea3e51a Merge pull request #3044 from stoeckmann/util_windows_toctou
util: Fix GetTempPathW TOCTOU race condition
2026-05-19 17:16:28 +02: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
Tobias Stoeckmann 7eeaced525 Merge pull request #3038 from stoeckmann/tar_util_string
tar: Improve string safety in list_item_verbose
2026-05-16 21:40:12 +02:00
Tobias StoeckmannandTim Kientzle a612bf62f8 rar: Fix heap-buffer-overflow (#2599)
A filter block size must not be larger than the lzss window, which is
defined
by dictionary size, which in turn can be derived from unpacked file
size.

While at it, improve error messages and fix lzss window wrap around
logic.

Fixes https://github.com/libarchive/libarchive/issues/2565

---------

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Co-authored-by: Tim Kientzle <kientzle@acm.org>
2025-05-11 19:00:11 +02:00
Tobias Stoeckmann 09685126fc rar: Fix double free with over 4 billion nodes (#2598)
If a system is capable of handling 4 billion nodes in memory, a double
free could occur because of an unsigned integer overflow leading to a
realloc call with size argument of 0. Eventually, the client will
release that memory again, triggering a double free.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-10 17:17:19 -07:00
Tobias Stoeckmann 1d7eadf417 Fix archive_time.c issues (concurrency, 32 bit) (#2563)
The refactoring of https://github.com/libarchive/libarchive/pull/2553
introduced three issues:

1. Introduction of a modifiable global static variable

This violates the goal of having no global variables as stated in [the
README.md](https://github.com/libarchive/libarchive/blob/b6f6557abb8235f604eced6facb42da8c7ab2a41/README.md?plain=1#L195)
which in turn leads to concurrency issues. Without any form of mutex
protection, multiple threads are not guaranteed to see the correct
min/max values. Since these are not needed in regular use cases but only
in edge cases, handle them in functions with local variables only.

Also the global variables are locale-dependent which can change during
runtime. In that case, future calls leads to issues.

2. Broken 32 bit support

The writers for zip and others affected by the previously mentioned PR
and test-suite on Debian 12 i686 are broken, because the calculation of
maximum MS-DOS time is not possible with a 32 bit time_t. Treat these
cases properly.

3. Edge case protection

Huge or tiny int64_t values can easily lead to unsigned integer
overflows. While these do not affect stability of libarchive, the
results are still wrong, i.e. are not capped at min/max as expected.

In total, the functions are much closer to their original versions again
(+ more range checks).

---------

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-09 13:33:32 +02:00
Tobias Stoeckmann 3e4683f5c4 rar: Check packed_size constraints (#2591)
Make sure that size_t casts do not truncate the value of packed_size on
32 bit systems since it's 64 bit. Extensions to RAR format allow 64 bit
values to be specified in archives.

Also verify that 64 bit signed arithmetics do not overflow.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-09 13:31:24 +02:00
Tobias Stoeckmann 2b8db0f82d rar: Fix rar_read_ahead call stack overflow (#2592)
It is possible to trigger a call stack overflow by repeatedly entering
the rar_read_ahead function. In normal circumstances, this recursion is
optimized away by common compilers, but default settings with MSVC keep
the recursion in place. Explicitly turn the recursion into a goto-loop
to avoid the overflow even with no compiler optimizations.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-09 13:31:00 +02:00
Tobias Stoeckmann 4f4e0e4b70 rar: Clean up br on split archive entries (#2593)
Reset avail_in and next_in if the next entry of a split archive is
parsed to always update its internal structure to access next bytes when
cache runs empty.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-09 13:30:32 +02:00
Tobias Stoeckmann e744746cc1 rar: Support large headers on 32 bit systems (#2596)
Support header sizes larger than 32 bit even on 32 bit systems, since
these normally have large file support. Otherwise an unsigned integer
overflow could occur, leading to erroneous parsing on these systems.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-09 13:29:53 +02:00
Tobias Stoeckmann 761e2f3c1e Unify spacing in archive_read_support_format_rar.c (#2590)
Most source files use tabs instead of spaces, but
archive_read_support_format_rar.c uses spaces most of the time. A few
lines contain a mixture of tabs and spaces, which leads to poorly
formatted output with many default settings.

Unify the style. No functional change and preparation for upcoming
changes to get rid of white space diffs.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-04-27 16:22:34 -07:00
Tobias Stoeckmann dcbf1e0ede Do not skip past EOF while reading (#2584)
Make sure to not skip past end of file for better error messages. One
such example is now visible with rar testsuite. You can see the
difference already by an actually not useless use of cat:

```
$ cat .../test_read_format_rar_ppmd_use_after_free.rar | bsdtar -t
bsdtar: Archive entry has empty or unreadable filename ... skipping.
bsdtar: Archive entry has empty or unreadable filename ... skipping.
bsdtar: Truncated input file (needed 119 bytes, only 0 available)
bsdtar: Error exit delayed from previous errors.
```

compared to

```
$ bsdtar -tf .../test_read_format_rar_ppmd_use_after_free.rar
bsdtar: Archive entry has empty or unreadable filename ... skipping.
bsdtar: Archive entry has empty or unreadable filename ... skipping.
bsdtar: Error exit delayed from previous errors.
```

Since the former cannot lseek, the error is a different one
(ARCHIVE_FATAL vs ARCHIVE_EOF). The piped version states explicitly that
truncation occurred, while the latter states EOF because the skip past
the end of file was successful.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-04-14 21:02:17 -07:00
Tobias Stoeckmann e1c8c9ef64 tar: Improve LFS support on 32 bit systems (#2582)
The size_t data type is only 32 bit on 32 bit sytems while off_t is
generally 64 bit to support files larger than 2 GB.

If an entry is declared to be larger than 4 GB and the entry shall be
skipped, then 32 bit systems truncate the requested amount of bytes.
This leads to different interpretation of data in tar files compared to
64 bit systems.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-04-13 11:07:18 -07:00
Tobias Stoeckmann ef09372952 warc: Prevent signed integer overflow (#2568)
If a warc archive claims to have more than INT64_MAX - 4 content bytes,
the inevitable failure to skip all these bytes could lead to parsing
data which should be ignored instead.

The test case contains a conversation entry with that many bytes and if
the entry is not properly skipped, the warc implementation would read
the conversation data as a new file entry.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-04-06 15:24:13 -07:00
Tobias Stoeckmann 89b8c35ff4 Improve lseek handling (#2564)
The skip functions are limited to 1 GB for cases in which libarchive
runs on a system with an off_t or long with 32 bits. This has negative
impact on 64 bit systems.

Instead, make sure that _all_ subsequent functions truncate properly.
Some of them already did and some had regressions for over 10 years.

Tests pass on Debian 12 i686 configured with --disable-largefile, i.e.
running with an off_t with 32 bits.

Casts added where needed to still pass MSVC builds.

---------

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-04-06 13:34:37 -07:00
Tobias Stoeckmann a88e09a370 Remove extra newline from error messages (#2541)
The lafe_errc function adds a newline by itself already, so do not
insert one into the message.

You can reproduce with the following commands:

```
touch archive.tar
bsdtar -xf archive.tar -C /non-existing
```

```
bsdtar --exclude ""
```

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-03-16 15:33:05 -07:00
Tobias Stoeckmann 13e8fc669b b64encode: Fix typo in error message (#2281)
If this function fails, log b64encode instead of uu.
2024-08-12 15:22:12 -07:00
Tobias Stoeckmann 9a3bce888b rar: Fix Visual Studio compiler warning (#2188)
Fixes the following warning:

warning C4244: '=': conversion from 'int64_t' to 'size_t', possible loss
of data
2024-06-02 20:06:31 -07:00
Tobias Stoeckmann edbb1fd452 Plug memory leaks (#2183)
The parsers for 7zip and xar contain memory leaks. Also the testsuite
7zip leaks memory. Plug them.

Noticed while running test suite with address sanitizer on Linux.
2024-06-02 16:49:26 -07:00
Tobias Stoeckmann 9cbe1627ca rar5: Fix Visual Studio compiler warnings (#2187)
Turning window_mask into ssize_t and adjusting the signature of
circular_memcpy reduces the amount of required casts. Since window_mask
depends on value window_size, which is ssize_t, this change is safe.

Also turned extra_data_size into int64_t, which is a no-op on 64 bit
systems but prevents 32 bit systems from truncating these huge values in
archives. Since these systems most likely have large file support, this
could have meant truncation -- in theory.
2024-06-02 16:43:38 -07:00
Tobias Stoeckmann 1aafde5923 Fix EOF handling of __archive_read_ahead (#2196)
Reaching EOF for first time sets the correct amount of available bytes,
but each subsequent call returns 0.

Do not forget that the copy buffer can already contain data and return
the amount of bytes left in there.

See added test case.
2024-06-02 16:35:41 -07:00
Tobias Stoeckmann 3af83ee6e7 7zip: Fix DONT_FAIL_ON_CRC_ERROR check (#2197)
This actually disabled CRC checks on regular builds and enabled it if
CRC checks were supposed to be disabled.

All other occurrences properly use ifndef instead of ifdef.
2024-06-02 16:30:14 -07:00
Tobias Stoeckmann 582190e4a7 rar: Fix OOB access with unicode filenames (#2203)
Prevent out of boundary accesses by revalidating offset every time it is
incremented.
2024-06-02 16:28:45 -07:00
Tobias Stoeckmann ed743f63fd Check realloc return values (#2204)
If realloc fails, keep track of currently allocated memory instead of
provoking memory leaks in error paths.
2024-06-02 16:21:30 -07:00
Tobias Stoeckmann 8fc0569bab 7zip: Fix NULL pointer dereference on non-zlib builds (#2193)
If libarchive is built without zlib support, it is possible to trigger a
NULL pointer dereference with specially crafted 7zip files.

It takes multiple conditions to be able to reach the issue in crc32 and
all 7zip-specific ones are fixed with this PR.
2024-05-17 21:43:47 -07:00
Tobias Stoeckmann 17333c27ad cab: Cover all error cases in __archive_read_ahead (#2194)
If a short read is performed, fail with truncation error message as
well.
2024-05-17 21:37:14 -07:00
Tobias Stoeckmann adf7388139 xar: Switch from int to size_t API (#2195)
Most of the functions already use size_t for sizes. Do the same for
xml_data. The libraries expat and libxml2 do not support strings larger
than 2 GB (limit is less than this) but it fixes one last Visual Studio
compiler warning which I missed previously.
2024-05-17 21:36:22 -07:00
Tobias Stoeckmann d33f44ad5c zip: Fix Visual Studio compiler warnings (#2186)
Use casts where appropriate (values cannot exceed data type limits).

Fixes following warnings:

warning C4244: '=': conversion from 'int64_t' to 'long', possible loss
of data
warning C4244: '=': conversion from 'uint64_t' to 'size_t', possible
loss of data
2024-05-14 19:59:03 -07:00
Tobias Stoeckmann aa02684709 xar: Fix Visual Studio compiler warnings (#2190)
Cast to proper types as used in these structs and function prototype.
2024-05-14 19:57:25 -07:00
Tobias StoeckmannandDuncan Horn 69c171a5ab Fix Visual Studio compiler warnings (64 bit) (#2189)
Some warnings are specific to 64 bit systems. Compiled with Visual
Studio 2022 on Windows 11 x64.

Co-authored-by: Duncan Horn <dunhor@microsoft.com>
2024-05-14 19:55:51 -07:00
Tobias Stoeckmann 1d6e5d117a rpm: Fix Visual Studio compiler warnings (#2181)
Adjust type of variables for their specific use case
Add a new inline function to unify casting (and clarify code blocks)
Use definition to explain magic number (and reduce casts)
Use `hpos` instead of magic number to highlight that additional bytes
will be parsed
2024-05-13 08:46:04 +02:00
Tobias StoeckmannandDuncan Horn 3085a3e9d3 [Windows] Fix test compilation warnings with Visual Studio (#2178)
Fixes all test-related compiler warnings with Visual Studio 2022 on
Windows 11.

Contains some changes from
https://github.com/libarchive/libarchive/pull/2095.

CC: @dunhor

---------

Co-authored-by: Duncan Horn <dunhor@microsoft.com>
2024-05-12 12:26:19 -07:00
Tobias Stoeckmann 34338d6c4b rar: Fix out ouf boundary access with large files (#2179)
If a header has the FHD_LARGE flag set, it is not verified that enough
bytes have been read. Check boundaries before accessing the additional
bytes.
2024-05-11 10:12:03 -07:00
Tobias Stoeckmann cd95ec3b72 uu: Fix Visual Studio compiler warning (#2180)
Switch from int64_t to ssize_t for l and body, which is a no-op on 64
bit systems. On 32 bit systems, this change is okay because these
variables interact with other ssize_t variables in this scope.

Fixes compiler warning regarding line 584 in which ssize_t and int64_t
are mixed in calculations:

warning C4244: '=': conversion from 'int64_t' to 'long'
2024-05-11 10:06:04 -07:00
Tobias Stoeckmann dee8b59108 7zip: Fix Visual Studio compiler warnings (#2182)
The cast in ppmd_read function is safe even on 32 bit systems. It is
called byte for byte which makes it impossible to actually reach
SIZE_MAX on any real world hardware.

Fixes Visual Studio warnings:

warning C4244: '=': conversion from 'uint64_t' to 'size_t', possible
loss of data
warning C4244: 'function': conversion from 'int64_t' to 'size_t',
possible loss of data
2024-05-11 09:53:02 -07:00
Tobias Stoeckmann 576a242050 shar: Check strdup return value (#2173)
The strdup function could fail, so check for NULL return value.
2024-05-10 01:49:50 +02:00
Tobias Stoeckmann 8bc1a3e66e lzop: Prevent integer overflow (#2174)
Cast to int64_t to cover all unsigned 32 bit values without running into
issues with C standard.
2024-05-10 01:49:07 +02:00
Tobias Stoeckmann dd8f50c317 unzip: Unify EOF handling (#2175)
If EOF is encountered while reading the new filename after choosing 'r',
avoid out of boundary access and usage of undefined memory content by
treating it the same way as if the question itself was not answered.
2024-05-10 01:32:09 +02:00
Tobias Stoeckmann 47be31fb1c Fix typos (#2169)
Remove duplicated "of" in write-filter comments.
2024-05-05 15:41:25 -07:00
Tobias Stoeckmann 1e406c9ea2 uu: Stop processing if lines are too long (#2168)
Processing excessively long lines could lead to out of boundary writes
or denial of service due to O(n^2) runtime complexity.

The OOB is properly fixed with first commit. The second commit stops
processing of lines which are longer than uu allows due to its
specification.
2024-05-05 15:40:57 -07:00
Tobias Stoeckmann 6818dd167c lha: Fix integer truncation on 32 bit systems (#2161)
The comp size could be around INT_MAX on huge archives, which would lead
to eventual integer truncation to size_t in archives with version 1
headers when fixed value 2 is added to comp_size on 32 bit systems.

This fix is a no-op on 64 bit systems because size_t and uint64_t are of
same size there.
2024-05-04 12:17:21 -07:00
Tobias Stoeckmann 9a50ce48b6 Fix typos (#2165)
Typos found with codespell.
2024-05-04 10:58:25 -07:00
Tobias Stoeckmann bad9a4ebb6 Fix out of boundary access in mktemp functions (#2160)
Some of the mktemp-related functions might access memory out of bounds
if TMPDIR is empty or other such situations lead to an empty
archive_string.
2024-05-03 15:19:55 -07:00
Tobias Stoeckmann 80af74ccbf zip: Improve bid for huge EOCDs (#2159)
Cast any of cd_offset or cd_size to int64_t to avoid truncation of
result because both variables are of type uint32_t.

The calculation happens before comparison with current_offset, so it is
not automatically expanded to int64_t during calculation.
2024-05-03 15:18:34 -07:00
Tobias Stoeckmann b9f713540c rpm: Calculate huge header sizes correctly (#2158)
If an RPM file contains a huge header which is larger than 4 GB then
libarchive starts parsing the RPM header as actual archive instead of
skipping it.

Switched to uint64_t from size_t for proper 32 bit support as well.
2024-05-03 14:41:35 -07:00
Tobias Stoeckmann 93b11caed8 lha: Do not allow negative file sizes (#2155)
Files sizes cannot be negative, so abort lha processing if archive
claims otherwise.
2024-04-29 22:06:30 +02:00
Tobias Stoeckmann 287e05d539 archive_match: Turn counter into flag (#2154)
When working with matches, the code does not care about the actual
amount of times when it matched, but just if it matched so far at least
once or never.

Turning the counter into a boolean flag has the advantage that even
insanely huge archives will never lead to integer overflow here.
2024-04-29 22:05:44 +02:00
Tobias Stoeckmann 0ce1b4c382 archive_match: check archive_read_support_format_raw() return value (#2153)
If call of archive_read_support_format_raw fails, do not override the
error return value with the return value of
archive_read_support_format_empty(). Instead, return error code as expected.
2024-04-29 22:00:22 +02:00
Tobias Stoeckmann b910cb70d4 xar: Fix another infinite loop and expat error handling (#2150)
Fixes two issues:
- expat code keeps track of error conditions
- adding link=original multiple times is prohibited
2024-04-28 23:48:05 +02:00
Tobias Stoeckmann f673faefaa Fix typos (#2143)
Fix typos in comments, documentation, and error messages.
2024-04-25 11:22:45 +02:00
Tobias Stoeckmann 5cc96c955a warc: Check realloc return value (#2144)
Since realloc could fail, check its return value and set a proper error
message.
2024-04-25 11:20:23 +02:00
Tobias Stoeckmann b6a979481b zip: Fix out of boundary access (#2145)
If a ZIP file contains a file with an empty name and mac-ext option is
set, then a check accesses memory out of bound of `name`.
2024-04-25 11:18:30 +02:00
Tobias Stoeckmann ae4e3d2f0d 7zip: Limit amount of properties (#2131)
The uint64_t variable propertiesSize is eventually casted to size_t
which, on 32 bit systems, can result in integer truncation.

In such a situation, it is possible that less than the minimum of 5
properties are parsed and processed, which will result in out of
boundary reads in init_decompression because the error check `if
(coder1->propertiesSize < 5)` still takes the uint64_t variable into
account.
2024-04-20 15:39:38 -07:00
Tobias Stoeckmann 27d2ff3b6b [Windows] Ignore more directories generated by Visual Studio (#2133)
Compiling libarchive with Visual Studio (not Visual Studio Code)
generates files in different directories.

Ignore these as well.
2024-04-19 08:12:59 -07:00
Tobias Stoeckmann 1a2fd29f6d Never allow empty passwords (#2116)
Passwords for encryption must not be empty. Neither through command line
option nor through interactive input.

With this PR applied:
```
$ bsdtar --format zip --options zip:encryption -cf archive.zip input.txt
Enter passphrase: <press enter>
bsdtar: Encryption needs passphrase
```

Output with command line argument (unaffected by this PR):
```
$ bsdtar --format zip --options zip:encryption --passphrase '' -cf archive.zip input.txt
bsdtar: Empty passphrase is unacceptable
```

The outputs differ due to internal difference in handling the results.

It is still possible to supply a passphrase through command line
argument which cannot be entered interactively, i.e. $'\r\n'. See
https://github.com/libarchive/libarchive/pull/2115 for more details.
2024-04-12 22:44:51 -07:00
Tobias Stoeckmann 46818684c3 Improve newline handling on Windows (#2115)
If libarchive is compiled on Windows without cygwin, strip \r and \n the
same way as it is done on POSIX systems.

Also, entering an empty password as "\r\n" should lead to an empty
string. Right now, the newlines are kept.

Proof of Concept:

1. Compile libarchive with Visual Studio
2. Create a password-protected ZIP file
```
PS> bsdtar.exe --format zip --options 'zip:encryption' -cf archive.zip input.txt
Enter passphrase: <press enter>
```
3. Extract ZIP file on Windows
```
PS> bsdtar.exe -xf archive.zip
Enter passphrase: <press enter>
```
4. Extract ZIP file on Linux
```
$ bsdtar -xf archive.zip
Enter passphrase: <press enter>
Enter passphrase:
```

As can be seen in step 4, it is impossible to extract the file on Linux
with interactive input, because \r and \n are stripped.
The only way to extract the content is through command line option
passphrase:
```
$ bsdtar -xf archive.zip --passphrase $'\r\n'
```

It's also true the other way around: Creating a ZIP file with an empty
password on Linux cannot be extracted interactively on Windows. Not
allowing empty passwords at all should be part of another PR. This one
is about unifying Windows and POSIX systems regarding newline handling.
2024-04-12 22:40:02 -07:00
Tobias Stoeckmann f4d5aaed1e [Windows] Ignore files generated by Visual Studio with CMake (#2120)
These files are created when building libarchive within Visual Studio
Code, its CMake plugin and Visual Studio 2022 as compiler.

Without this change, Visual Studio Code shows hundreds of files in
GitLense plugin waiting to be commited.
2024-04-12 22:26:53 -07:00
Tobias Stoeckmann bd974e1b7b tools: Fix stack overflow with many arguments (#2122)
Supplying a lot of "-" arguments to tools can lead to stack overflow due
to recursive *_getopt function calls.

Proof of Concept:

1. Compile libarchive with Visual Studio 2022
2. Call bsdtar with insane amount of arguments
```
PS> bsdtar.exe ("- "*10000).split(" ")
```
The event log shows that bsdtar.exe failed with `0xc00000fd` (stack
overflow).

If compiled with gcc, this does not happen by default because the code
is internally optimized to use this suggested loop instead. You have to
compile with CFLAGS="-O0" to provoke it with gcc as well.
2024-04-12 22:15:53 -07:00
Tobias Stoeckmann 7bc8531da4 Prevent usage of uninitialized variable in __archive_mkstemp (#2121)
Calling `__archive_mkstemp` can lead to access of an uninitialized
variable in `__archive_mktempx`, because `temp_name` is only initialized
if supplied `template` argument is `NULL`.

If `template` is not `NULL`, it is eventually compared with
`temp_name.s` anyway.

The fix is simple: Always initialize `temp_name`, which merely sets
values in the struct. No memory allocation occurs and the check leads to
the expected result.

How to reproduce:

1. Compile libarchive with Visual Studio 2022 and CMake's Debug profile
2. Run test `bsdtar_test_option_safe_writes`
3. A popup (Microsoft Visual C++ Runtime Library) appears, stating that
variable temp_name is being used without being initialized
2024-04-12 22:14:59 -07:00