]> git.ipfire.org Git - thirdparty/libarchive.git/log
thirdparty/libarchive.git
13 months agoSupport ISOs with a non-standard PVD layouts (#2238)
Tim Kientzle [Mon, 17 Jun 2024 03:22:14 +0000 (20:22 -0700)] 
Support ISOs with a non-standard PVD layouts (#2238)

The CSRG ISOs have a non-standard PVD layout with a 68-byte root
directory record (rather than the 34-byte record required by
ECMA119/ISO9660). I built a test image with this change and modified the
ISO9660 reader to accept it.

While I was working on the bid logic to recognize PVDs, I added a number
of additional correctness checks that should make our bidding a bit more
accurate. In particular, this should more than compensate for the
weakened check of the root directory record size.

Resolves #2232

13 months agoParse tar headers incrementally (#2127)
Tim Kientzle [Sun, 16 Jun 2024 05:22:12 +0000 (22:22 -0700)] 
Parse tar headers incrementally (#2127)

This rebuilds the tar reader to parse all header data incrementally as
it appears in the stream.

This definitively fixes a longstanding issue with unsupported pax
attributes. Libarchive must limit the amount of data that it reads into
memory, and this has caused problems with large unknown attributes. By
scanning iteratively, we can instead identify an attribute by name and
then decide whether to read it into memory or whether to skip it without
reading.

This design also allows us to vary our sanity limits for different pax
attributes (e.g., an attribute that is a single number can be limited to
a few dozen bytes while an attribute holding an ACL is allowed to be a
few hundred kilobytes). This allows us to be a little more resistant to
malicious archives that might try to force allocation of very large
amounts of memory, though there is still work to be done here.

This includes a number of changes to archive_entry processing to allow
us to consistently keep the _first_ appearance of any given value
instead of the original architecture that recursively cached data in
memory in order to effectively process all the data from back-to-front.

Resolves #1855
Resolves #1939

13 months agoFix a couple issues with creating PAX archives (#2228)
Duncan Horn [Sun, 16 Jun 2024 05:20:00 +0000 (22:20 -0700)] 
Fix a couple issues with creating PAX archives (#2228)

Note: this is a partial cherry-pick from
https://github.com/libarchive/libarchive/pull/2095, which I'm going to
go through and break into smaller pieces in hopes of getting some things
in while discussion of other things can continue.

There's basically two fixes here:

The first is to check for the presence of the WCS pathname on Windows
before failing since the conversion from WCS -> MBS might fail. Later
execution already handles such paths correctly.

The second is to set the converted link name on the target entry where
relevant. Note that there has been prior discussion on this here:
https://github.com/libarchive/libarchive/pull/2095/files#r1531599325

13 months agorar: fix UB negation overflow for INT32_MIN address (#2235)
alice [Sat, 15 Jun 2024 00:26:14 +0000 (02:26 +0200)] 
rar: fix UB negation overflow for INT32_MIN address (#2235)

certain rar files seem to have the lowest possible address here, so flip
the argument order to correctly evaluate this instead of invoking UB
(caught via sanitize=undefined)

---

the backtrace looks something like:

```
* frame #0: 0x00007a1e3898727b libarchive.so.13`execute_filter [inlined] execute_filter_e8(filter=<unavailable>, vm=<unavailable>, pos=<unavailable>, e9also=<unavailable>) at archive_read_support_format_rar.c:3640:47
    frame #1: 0x00007a1e3898727b libarchive.so.13`execute_filter(a=<unavailable>, filter=0x00007a1e39e2f090, vm=0x00007a1e31b1efd0, pos=<unavailable>) at archive_read_support_format_rar.c:0
    frame #2: 0x00007a1e38983ac3 libarchive.so.13`read_data_compressed [inlined] run_filters(a=0x00007a1e34209700) at archive_read_support_format_rar.c:3395:8
    frame #3: 0x00007a1e38983a9e libarchive.so.13`read_data_compressed(a=0x00007a1e34209700, buff=0x00007a1e31a01fd8, size=0x00007a1e31a01fd0, offset=0x00007a1e31a01fc0, looper=1) at archive_read_support_format_rar.c:2083:12
    frame #4: 0x00007a1e38981b10 libarchive.so.13`archive_read_format_rar_read_data(a=0x00007a1e34209700, buff=0x00007a1e31a01fd8, size=0x00007a1e31a01fd0, offset=0x00007a1e31a01fc0) at archive_read_support_format_rar.c:1130:11
    frame #5: 0x00006158bc5d30d3 file-roller`extract_archive_thread(result=0x00007a1e3711e2b0, object=<unavailable>, cancellable=0x00007a1e3870bf20) at fr-archive-libarchive.c:999:17
    frame #6: 0x00007a1e39928d6d libgio-2.0.so.0`run_in_thread(job=<unavailable>, c=<unavailable>, _data=0x00007a1e326e9740) at gsimpleasyncresult.c:899:5
    frame #7: 0x00007a1e3990614e libgio-2.0.so.0`io_job_thread(task=<unavailable>, source_object=<unavailable>, task_data=0x00007a1e2307fc20, cancellable=<unavailable>) at gioscheduler.c:75:16
    frame #8: 0x00007a1e399433bf libgio-2.0.so.0`g_task_thread_pool_thread(thread_data=0x00007a1e35c18ab0, pool_data=<unavailable>) at gtask.c:1583:3
    frame #9: 0x00007a1e39db77e8 libglib-2.0.so.0`g_thread_pool_thread_proxy(data=<unavailable>) at gthreadpool.c:336:15
    frame #10: 0x00007a1e39db5bfb libglib-2.0.so.0`g_thread_proxy(data=0x00007a1e378147d0) at gthread.c:835:20
    frame #11: 0x00007a1e3a0b5c7b ld-musl-x86_64.so.1`start(p=0x00007a1e31a02170) at pthread_create.c:208:17
    frame #12: 0x00007a1e3a0b8a8b ld-musl-x86_64.so.1`__clone + 47
```

note the 0xd which is 14 which is NegateOverflow in ubsan:

```
(lldb) x/1i $pc
->  0x7a1e3898727b: 67 0f b9 40 0d  other       ud1l   0xd(%eax), %eax
```

for reference, the totally legal rar file is
https://img.ayaya.dev/05WYGFOcRPN9 , and this seems to only crash when
extracted via file-roller (or inside nautilus)

13 months agoxar: guard against file entries containing multiple name elements (#2236)
Dustin L. Howett [Sat, 15 Jun 2024 00:13:42 +0000 (19:13 -0500)] 
xar: guard against file entries containing multiple name elements (#2236)

It appears that there are xar archives (in the form of Apple .pkg files)
that contain TOCs with duplicated name elements:

```xml
<file id="25">
  <data> ... </data>
  <type>file</type>
  <name>PackageInfo</name>
  <name>PackageInfo</name>
  <name>PackageInfo</name>
</file>
```

When libarchive encounters one such file, it will produce an
archive_entry named PackageInfoPackageInfoPackageInfo.

To produce a test archive, the XAR writer was modified to emit two name
elements.

13 months agoUpdate ustar creation sanity check to use WCS path on Windows (#2230)
Duncan Horn [Wed, 12 Jun 2024 19:01:40 +0000 (12:01 -0700)] 
Update ustar creation sanity check to use WCS path on Windows (#2230)

On Windows, the MBS pathname might be null if the string was set with a
WCS that can't be represented by the current locale. This is handled
properly by the rest of the code, but there's a sanity check that does
not make the proper distinction.

Note: this is a partial cherry-pick from
https://github.com/libarchive/libarchive/pull/2095, which I'm going to
go through and break into smaller pieces in hopes of getting some things
in while discussion of other things can continue.

13 months agoAdd unicode test for creating zip files on Windows (#2231)
Duncan Horn [Wed, 12 Jun 2024 19:00:24 +0000 (12:00 -0700)] 
Add unicode test for creating zip files on Windows (#2231)

There's no bug fix here - this just adds a test to verify that zip
creation when using the _w functions works as expected on Windows.

Note: this is a partial cherry-pick from
https://github.com/libarchive/libarchive/pull/2095, which I'm going to
go through and break into smaller pieces in hopes of getting some things
in while discussion of other things can continue.

13 months agoFuzzing: Expose `DONT_FAIL_ON_CRC_ERROR` as a CMake option and honor it in the rar5...
Mrmaxmeier [Wed, 12 Jun 2024 18:57:20 +0000 (20:57 +0200)] 
Fuzzing: Expose `DONT_FAIL_ON_CRC_ERROR` as a CMake option and honor it in the rar5 decoder (#2229)

Hey,

the fuzzing infrastructure over at OSSFuzz builds libarchive with the
CMake option `-DDONT_FAIL_ON_CRC_ERROR=1`.

https://github.com/google/oss-fuzz/blob/e4643b64b3af4932bff23bb87afdfbac2a301969/projects/libarchive/build.sh#L35
This, unfortunatly, does not do anything since it's never been defined
as an option.

Building the fuzzers with CRC checks disabled should improve fuzzing
efficacy a bunch.

Thanks!

13 months agoUse calloc instead of malloc to clear the memory from leftovers (#2207)
Lukas Javorsky [Tue, 11 Jun 2024 04:41:25 +0000 (06:41 +0200)] 
Use calloc instead of malloc to clear the memory from leftovers (#2207)

This ensures that the buffer is properly initialized and does not
contain any leftover data from previous operations. It is used later in
the `archive_entry_copy_hardlink_l` function call and could be
uninitialized.

13 months agoconfigure.ac: autoupdate (#2223)
Sevan Janiyan [Tue, 11 Jun 2024 04:35:49 +0000 (05:35 +0100)] 
configure.ac: autoupdate (#2223)

Clear up the autoconf warnings.

13 months agoUpdate archive_entry_link_resolver to copy the "wide" pathname for hardlinks on Windo...
Duncan Horn [Tue, 11 Jun 2024 04:23:13 +0000 (21:23 -0700)] 
Update archive_entry_link_resolver to copy the "wide" pathname for hardlinks on Windows (#2225)

On Windows, if you are using `archive_entry_link_resolver` and give it
an entry that links to past entry whose pathname was set using a "wide"
string that cannot be represented by the current locale (i.e. WCS -> MBS
conversion fails), this code will crash due to a null pointer read. This
updates to use the `_w` function instead on Windows.

Note: this is a partial cherry-pick from
https://github.com/libarchive/libarchive/pull/2095, which I'm going to
go through and break into smaller pieces in hopes of getting some things
in while discussion of other things can continue.

13 months agoAlways use our supplied la_queue.h (#2222)
Sevan Janiyan [Tue, 11 Jun 2024 03:42:13 +0000 (04:42 +0100)] 
Always use our supplied la_queue.h (#2222)

On legacy systems the OS supplied `sys/queue.h` may lack the required
macros, so to avoid having to verify if the version of queue.h is of
use, opt to always to `la_queue.h` which will match expectations.

Allows libarchive to build on legacy Darwin where `STAILQ_FOREACH` would
be missing from `sys/queue.h`.

Resolves #2220

13 months agoFix compilation when using Clang in "MSVC mode" (#2221)
Duncan Horn [Sat, 8 Jun 2024 19:41:04 +0000 (12:41 -0700)] 
Fix compilation when using Clang in "MSVC mode" (#2221)

When using Clang in "MSVC mode" (i.e. clang-cl), command line arguments
are interpreted as MSVC would interpret them, at least when there are
conflicts. This means that `-Wall` - potentially among other switches -
is interpreted _dramatically_ differently by clang-cl compared to
"normal" Clang.

In CMake, this can be detected by testing for `if (MSVC)` in addition to
compiler id test, which is what I do here.

Note: this is a partial cherry-pick from #2095, which I'm going to go
through and break into smaller pieces in hopes of getting some things in
while discussion of other things can continue.

14 months agoFix tar -w on Windows (#2219)
Dustin L. Howett [Tue, 4 Jun 2024 03:27:29 +0000 (22:27 -0500)] 
Fix tar -w on Windows (#2219)

The tar utility reads from stderr to receive user input even when stdin
is a pipe. That is unfortunately unsupported on Windows.

The nearest equivalent is to reopen and read from the console input
handle.

Closes #2215

14 months agoTest on FreeBSD 13.3 (#2216)
Tim Kientzle [Mon, 3 Jun 2024 07:59:10 +0000 (00:59 -0700)] 
Test on FreeBSD 13.3 (#2216)

CI: Update FreeBSD 13 to 13.3

14 months agorar: Fix Visual Studio compiler warning (#2188)
Tobias Stoeckmann [Mon, 3 Jun 2024 03:06:31 +0000 (05:06 +0200)] 
rar: Fix Visual Studio compiler warning (#2188)

Fixes the following warning:

warning C4244: '=': conversion from 'int64_t' to 'size_t', possible loss
of data

14 months agoFix handling a negative bytes_per_block values (#2206)
Lukas Javorsky [Sun, 2 Jun 2024 23:50:22 +0000 (01:50 +0200)] 
Fix handling a negative bytes_per_block values (#2206)

Related issue: https://github.com/libarchive/libarchive/issues/2185

14 months agoPlug memory leaks (#2183)
Tobias Stoeckmann [Sun, 2 Jun 2024 23:49:26 +0000 (01:49 +0200)] 
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.

14 months agorar5: Fix Visual Studio compiler warnings (#2187)
Tobias Stoeckmann [Sun, 2 Jun 2024 23:43:38 +0000 (01:43 +0200)] 
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.

14 months agoFix EOF handling of __archive_read_ahead (#2196)
Tobias Stoeckmann [Sun, 2 Jun 2024 23:35:41 +0000 (01:35 +0200)] 
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.

14 months ago7zip: Fix DONT_FAIL_ON_CRC_ERROR check (#2197)
Tobias Stoeckmann [Sun, 2 Jun 2024 23:30:14 +0000 (01:30 +0200)] 
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.

14 months agorar: Fix OOB access with unicode filenames (#2203)
Tobias Stoeckmann [Sun, 2 Jun 2024 23:28:45 +0000 (01:28 +0200)] 
rar: Fix OOB access with unicode filenames (#2203)

Prevent out of boundary accesses by revalidating offset every time it is
incremented.

14 months agoCheck realloc return values (#2204)
Tobias Stoeckmann [Sun, 2 Jun 2024 23:21:30 +0000 (01:21 +0200)] 
Check realloc return values (#2204)

If realloc fails, keep track of currently allocated memory instead of
provoking memory leaks in error paths.

14 months agorar reader: fix cast to unsigned int (#2209)
LukeSkyD [Fri, 31 May 2024 14:11:12 +0000 (16:11 +0200)] 
rar reader: fix cast to unsigned int (#2209)

Fixes compiler error `C4267: '+=': conversion from 'size_t' to 'unsigned int'.
Possible loss of data.` which stops compiling with MSVC.

14 months agoCI: Bump the all-actions group with 2 updates (#2198)
dependabot[bot] [Tue, 28 May 2024 09:42:32 +0000 (11:42 +0200)] 
CI: Bump the all-actions group with 2 updates (#2198)

Bumps the all-actions group with 2 updates:
 `actions/checkout` from 4.1.5 to 4.1.6
`github/codeql-action` from 3.25.5 to 3.25.6

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
14 months agofix(rar): add boundary checks to rgb filter (#2210)
Wei-Cheng Pan [Tue, 28 May 2024 09:40:32 +0000 (18:40 +0900)] 
fix(rar): add boundary checks to rgb filter (#2210)

`blocklength` should be bigger than `3` (channel count)
`byteoffset` should not be bigger than `2` (does not make sense as per the
last loop)
`src` should not overlap with `dst`.

There is no allocation in this function so it should be safe to return
early.

Security: GHSA-9qqv-q4qw-mf8m

14 months ago7zip: Fix NULL pointer dereference on non-zlib builds (#2193)
Tobias Stoeckmann [Sat, 18 May 2024 04:43:47 +0000 (06:43 +0200)] 
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.

14 months agocab: Cover all error cases in __archive_read_ahead (#2194)
Tobias Stoeckmann [Sat, 18 May 2024 04:37:14 +0000 (06:37 +0200)] 
cab: Cover all error cases in __archive_read_ahead (#2194)

If a short read is performed, fail with truncation error message as
well.

14 months agoxar: Switch from int to size_t API (#2195)
Tobias Stoeckmann [Sat, 18 May 2024 04:36:22 +0000 (06:36 +0200)] 
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.

14 months agozip: Fix Visual Studio compiler warnings (#2186)
Tobias Stoeckmann [Wed, 15 May 2024 02:59:03 +0000 (04:59 +0200)] 
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

14 months agoxar: Fix Visual Studio compiler warnings (#2190)
Tobias Stoeckmann [Wed, 15 May 2024 02:57:25 +0000 (04:57 +0200)] 
xar: Fix Visual Studio compiler warnings (#2190)

Cast to proper types as used in these structs and function prototype.

14 months agoFix Visual Studio compiler warnings (64 bit) (#2189)
Tobias Stoeckmann [Wed, 15 May 2024 02:55:51 +0000 (04:55 +0200)] 
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>
14 months agoCI: Bump the all-actions group with 3 updates (#2184)
dependabot[bot] [Tue, 14 May 2024 07:42:29 +0000 (09:42 +0200)] 
CI: Bump the all-actions group with 3 updates (#2184)

Updates `actions/checkout` from 4.1.4 to 4.1.5
Updates `github/codeql-action` from 3.25.3 to 3.25.5
Updates `ossf/scorecard-action` from 2.3.1 to 2.3.3

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
14 months agorpm: Fix Visual Studio compiler warnings (#2181)
Tobias Stoeckmann [Mon, 13 May 2024 06:46:04 +0000 (08:46 +0200)] 
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

14 months agoResolve TODO: Return uname and gname overrides (#2141)
Martin Matuška [Mon, 13 May 2024 06:44:28 +0000 (08:44 +0200)] 
Resolve TODO: Return uname and gname overrides (#2141)

Simplify introducing a struct cpio_owner

Co-authored-by: Rose <83477269+AtariDreams@users.noreply.github.com>
14 months ago[Windows] Fix test compilation warnings with Visual Studio (#2178)
Tobias Stoeckmann [Sun, 12 May 2024 19:26:19 +0000 (21:26 +0200)] 
[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>
14 months agorar: Fix out ouf boundary access with large files (#2179)
Tobias Stoeckmann [Sat, 11 May 2024 17:12:03 +0000 (19:12 +0200)] 
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.

14 months agouu: Fix Visual Studio compiler warning (#2180)
Tobias Stoeckmann [Sat, 11 May 2024 17:06:04 +0000 (19:06 +0200)] 
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'

14 months ago7zip: Fix Visual Studio compiler warnings (#2182)
Tobias Stoeckmann [Sat, 11 May 2024 16:53:02 +0000 (18:53 +0200)] 
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

14 months agounzip: do not use getenv() and setenv() in test_I.c (#2177)
Martin Matuška [Fri, 10 May 2024 01:00:33 +0000 (03:00 +0200)] 
unzip: do not use getenv() and setenv() in test_I.c (#2177)

This setenv() call may clobber the memory pointed to by lang.

It is also insufficient, since you don't run in a clean environment, so
LANG may be overridden by an inherited LC_ALL or LC_CTYPE, or by the
user's .profile (remember that system() does not execute the command
directly, but passes it to a shell).

Reported-By: dag-erling (quoting)
14 months agorar4 reader: protect copy_from_lzss_window_to_unp() (#2172)
Dustin L. Howett [Thu, 9 May 2024 23:59:17 +0000 (18:59 -0500)] 
rar4 reader: protect copy_from_lzss_window_to_unp() (#2172)

copy_from_lzss_window_to_unp unnecessarily took an `int` parameter where
both of its callers were holding a `size_t`.

A lzss opcode chain could be constructed that resulted in a negative
copy length, which when passed into memcpy would result in a very, very
large positive number.

Switching copy_from_lzss_window_to_unp to take a `size_t` allows it to
properly bounds-check length.

In addition, this patch also ensures that `length` is not itself larger
than the destination buffer.

Security: CVE-2024-20696

14 months agoshar: Check strdup return value (#2173)
Tobias Stoeckmann [Thu, 9 May 2024 23:49:50 +0000 (01:49 +0200)] 
shar: Check strdup return value (#2173)

The strdup function could fail, so check for NULL return value.

14 months agolzop: Prevent integer overflow (#2174)
Tobias Stoeckmann [Thu, 9 May 2024 23:49:07 +0000 (01:49 +0200)] 
lzop: Prevent integer overflow (#2174)

Cast to int64_t to cover all unsigned 32 bit values without running into
issues with C standard.

14 months agounzip: Unify EOF handling (#2175)
Tobias Stoeckmann [Thu, 9 May 2024 23:32:09 +0000 (01:32 +0200)] 
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.

14 months agoDefine INT_MAX via `#include <limits.h>` (#2170)
Tim Kientzle [Tue, 7 May 2024 03:46:26 +0000 (20:46 -0700)] 
Define INT_MAX via `#include <limits.h>` (#2170)

#2110 added usages of INT_MAX here without adding the necessary header.

Resolves #2162

15 months agoCI: Bump the all-actions group with 2 updates (#2152)
dependabot[bot] [Sun, 5 May 2024 22:56:25 +0000 (15:56 -0700)] 
CI: Bump the all-actions group with 2 updates (#2152)

Bumps the all-actions group with 2 updates:
[actions/checkout](https://github.com/actions/checkout) and
[github/codeql-action](https://github.com/github/codeql-action).

Updates `actions/checkout` from 4.1.3 to 4.1.4
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/actions/checkout/releases">actions/checkout's
releases</a>.</em></p>
<blockquote>
<h2>v4.1.4</h2>
<h2>What's Changed</h2>
<ul>
<li>Disable <code>extensions.worktreeConfig</code> when disabling
<code>sparse-checkout</code> by <a
href="https://github.com/jww3"><code>@​jww3</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1692">actions/checkout#1692</a></li>
<li>Add dependabot config by <a
href="https://github.com/cory-miller"><code>@​cory-miller</code></a> in
<a
href="https://redirect.github.com/actions/checkout/pull/1688">actions/checkout#1688</a></li>
<li>Bump word-wrap from 1.2.3 to 1.2.5 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1643">actions/checkout#1643</a></li>
<li>Bump the minor-actions-dependencies group with 2 updates by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1693">actions/checkout#1693</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/actions/checkout/compare/v4.1.3...v4.1.4">https://github.com/actions/checkout/compare/v4.1.3...v4.1.4</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/actions/checkout/blob/main/CHANGELOG.md">actions/checkout's
changelog</a>.</em></p>
<blockquote>
<h1>Changelog</h1>
<h2>v4.1.4</h2>
<ul>
<li>Disable <code>extensions.worktreeConfig</code> when disabling
<code>sparse-checkout</code> by <a
href="https://github.com/jww3"><code>@​jww3</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1692">actions/checkout#1692</a></li>
<li>Add dependabot config by <a
href="https://github.com/cory-miller"><code>@​cory-miller</code></a> in
<a
href="https://redirect.github.com/actions/checkout/pull/1688">actions/checkout#1688</a></li>
<li>Bump the minor-actions-dependencies group with 2 updates by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1693">actions/checkout#1693</a></li>
<li>Bump word-wrap from 1.2.3 to 1.2.5 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1643">actions/checkout#1643</a></li>
</ul>
<h2>v4.1.3</h2>
<ul>
<li>Check git version before attempting to disable
<code>sparse-checkout</code> by <a
href="https://github.com/jww3"><code>@​jww3</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1656">actions/checkout#1656</a></li>
<li>Add SSH user parameter by <a
href="https://github.com/cory-miller"><code>@​cory-miller</code></a> in
<a
href="https://redirect.github.com/actions/checkout/pull/1685">actions/checkout#1685</a></li>
<li>Update <code>actions/checkout</code> version in
<code>update-main-version.yml</code> by <a
href="https://github.com/jww3"><code>@​jww3</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1650">actions/checkout#1650</a></li>
</ul>
<h2>v4.1.2</h2>
<ul>
<li>Fix: Disable sparse checkout whenever <code>sparse-checkout</code>
option is not present <a
href="https://github.com/dscho"><code>@​dscho</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1598">actions/checkout#1598</a></li>
</ul>
<h2>v4.1.1</h2>
<ul>
<li>Correct link to GitHub Docs by <a
href="https://github.com/peterbe"><code>@​peterbe</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1511">actions/checkout#1511</a></li>
<li>Link to release page from what's new section by <a
href="https://github.com/cory-miller"><code>@​cory-miller</code></a> in
<a
href="https://redirect.github.com/actions/checkout/pull/1514">actions/checkout#1514</a></li>
</ul>
<h2>v4.1.0</h2>
<ul>
<li><a href="https://redirect.github.com/actions/checkout/pull/1396">Add
support for partial checkout filters</a></li>
</ul>
<h2>v4.0.0</h2>
<ul>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1067">Support
fetching without the --progress option</a></li>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1436">Update to
node20</a></li>
</ul>
<h2>v3.6.0</h2>
<ul>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1377">Fix: Mark
test scripts with Bash'isms to be run via Bash</a></li>
<li><a href="https://redirect.github.com/actions/checkout/pull/579">Add
option to fetch tags even if fetch-depth &gt; 0</a></li>
</ul>
<h2>v3.5.3</h2>
<ul>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1196">Fix:
Checkout fail in self-hosted runners when faulty submodule are
checked-in</a></li>
<li><a href="https://redirect.github.com/actions/checkout/pull/1287">Fix
typos found by codespell</a></li>
<li><a href="https://redirect.github.com/actions/checkout/pull/1369">Add
support for sparse checkouts</a></li>
</ul>
<h2>v3.5.2</h2>
<ul>
<li><a href="https://redirect.github.com/actions/checkout/pull/1289">Fix
api endpoint for GHES</a></li>
</ul>
<h2>v3.5.1</h2>
<ul>
<li><a href="https://redirect.github.com/actions/checkout/pull/1246">Fix
slow checkout on Windows</a></li>
</ul>
<h2>v3.5.0</h2>
<ul>
<li><a href="https://redirect.github.com/actions/checkout/pull/1237">Add
new public key for known_hosts</a></li>
</ul>
<h2>v3.4.0</h2>
<ul>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1209">Upgrade
codeql actions to v2</a></li>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1210">Upgrade
dependencies</a></li>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1225">Upgrade
<code>@​actions/io</code></a></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/actions/checkout/commit/0ad4b8fadaa221de15dcec353f45205ec38ea70b"><code>0ad4b8f</code></a>
Prep Release v4.1.4 (<a
href="https://redirect.github.com/actions/checkout/issues/1704">#1704</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/43045ae669be728bd34ed56fcd1a230c0dc4d8e2"><code>43045ae</code></a>
Disable <code>extensions.worktreeConfig</code> when disabling
<code>sparse-checkout</code> (<a
href="https://redirect.github.com/actions/checkout/issues/1692">#1692</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/37b082107ba410260a3aaddf93122e04801ce631"><code>37b0821</code></a>
Bump the minor-actions-dependencies group with 2 updates (<a
href="https://redirect.github.com/actions/checkout/issues/1693">#1693</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/9839dc14a02ddc6b6995e69eb3ecb98132fc8b6b"><code>9839dc1</code></a>
Add dependabot config (<a
href="https://redirect.github.com/actions/checkout/issues/1688">#1688</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/9b4c13b0bfa31b4514c14f74b5a166c2708f43c6"><code>9b4c13b</code></a>
Bump word-wrap from 1.2.3 to 1.2.5 (<a
href="https://redirect.github.com/actions/checkout/issues/1643">#1643</a>)</li>
<li>See full diff in <a
href="https://github.com/actions/checkout/compare/1d96c772d19495a3b5c517cd2bc0cb401ea0529f...0ad4b8fadaa221de15dcec353f45205ec38ea70b">compare
view</a></li>
</ul>
</details>
<br />

Updates `github/codeql-action` from 3.25.2 to 3.25.3
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/github/codeql-action/blob/main/CHANGELOG.md">github/codeql-action's
changelog</a>.</em></p>
<blockquote>
<h1>CodeQL Action Changelog</h1>
<p>See the <a
href="https://github.com/github/codeql-action/releases">releases
page</a> for the relevant changes to the CodeQL CLI and language
packs.</p>
<p>Note that the only difference between <code>v2</code> and
<code>v3</code> of the CodeQL Action is the node version they support,
with <code>v3</code> running on node 20 while we continue to release
<code>v2</code> to support running on node 16. For example
<code>3.22.11</code> was the first <code>v3</code> release and is
functionally identical to <code>2.22.11</code>. This approach ensures an
easy way to track exactly which features are included in different
versions, indicated by the minor and patch version numbers.</p>
<h2>[UNRELEASED]</h2>
<p>No user facing changes.</p>
<h2>3.25.3 - 25 Apr 2024</h2>
<ul>
<li>Update default CodeQL bundle version to 2.17.1. <a
href="https://redirect.github.com/github/codeql-action/pull/2247">#2247</a></li>
<li>Workflows running on <code>macos-latest</code> using CodeQL CLI
versions before v2.15.1 will need to either upgrade their CLI version to
v2.15.1 or newer, or change the platform to an Intel MacOS runner, such
as <code>macos-12</code>. ARM machines with SIP disabled, including the
newest <code>macos-latest</code> image, are unsupported for CLI versions
before 2.15.1. <a
href="https://redirect.github.com/github/codeql-action/pull/2261">#2261</a></li>
</ul>
<h2>3.25.2 - 22 Apr 2024</h2>
<p>No user facing changes.</p>
<h2>3.25.1 - 17 Apr 2024</h2>
<ul>
<li>We are rolling out a feature in April/May 2024 that improves the
reliability and performance of analyzing code when analyzing a compiled
language with the <code>autobuild</code> <a
href="https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages#codeql-build-modes">build
mode</a>. <a
href="https://redirect.github.com/github/codeql-action/pull/2235">#2235</a></li>
<li>Fix a bug where the <code>init</code> Action would fail if
<code>--overwrite</code> was specified in
<code>CODEQL_ACTION_EXTRA_OPTIONS</code>. <a
href="https://redirect.github.com/github/codeql-action/pull/2245">#2245</a></li>
</ul>
<h2>3.25.0 - 15 Apr 2024</h2>
<ul>
<li>
<p>The deprecated feature for extracting dependencies for a Python
analysis has been removed. <a
href="https://redirect.github.com/github/codeql-action/pull/2224">#2224</a></p>
<p>As a result, the following inputs and environment variables are now
ignored:</p>
<ul>
<li>The <code>setup-python-dependencies</code> input to the
<code>init</code> Action</li>
<li>The
<code>CODEQL_ACTION_DISABLE_PYTHON_DEPENDENCY_INSTALLATION</code>
environment variable</li>
</ul>
<p>We recommend removing any references to these from your workflows.
For more information, see the release notes for CodeQL Action v3.23.0
and v2.23.0.</p>
</li>
<li>
<p>Automatically overwrite an existing database if found on the
filesystem. <a
href="https://redirect.github.com/github/codeql-action/pull/2229">#2229</a></p>
</li>
<li>
<p>Bump the minimum CodeQL bundle version to 2.12.6. <a
href="https://redirect.github.com/github/codeql-action/pull/2232">#2232</a></p>
</li>
<li>
<p>A more relevant log message and a diagnostic are now emitted when the
<code>file</code> program is not installed on a Linux runner, but is
required for Go tracing to succeed. <a
href="https://redirect.github.com/github/codeql-action/pull/2234">#2234</a></p>
</li>
</ul>
<h2>3.24.10 - 05 Apr 2024</h2>
<ul>
<li>Update default CodeQL bundle version to 2.17.0. <a
href="https://redirect.github.com/github/codeql-action/pull/2219">#2219</a></li>
<li>Add a deprecation warning for customers using CodeQL version 2.12.5
and earlier. These versions of CodeQL were discontinued on 26 March 2024
alongside GitHub Enterprise Server 3.8, and will be unsupported by
CodeQL Action versions 3.25.0 and later and versions 2.25.0 and later.
<a
href="https://redirect.github.com/github/codeql-action/pull/2220">#2220</a>
<ul>
<li>If you are using one of these versions, please update to CodeQL CLI
version 2.12.6 or later. For instance, if you have specified a custom
version of the CLI using the 'tools' input to the 'init' Action, you can
remove this input to use the default version.</li>
<li>Alternatively, if you want to continue using a version of the CodeQL
CLI between 2.11.6 and 2.12.5, you can replace
<code>github/codeql-action/*@v3</code> by
<code>github/codeql-action/*@v3.24.10</code> and
<code>github/codeql-action/*@v2</code> by
<code>github/codeql-action/*@v2.24.10</code> in your code scanning
workflow to ensure you continue using this version of the CodeQL
Action.</li>
</ul>
</li>
</ul>
<h2>3.24.9 - 22 Mar 2024</h2>
<ul>
<li>Update default CodeQL bundle version to 2.16.5. <a
href="https://redirect.github.com/github/codeql-action/pull/2203">#2203</a></li>
</ul>
<h2>3.24.8 - 18 Mar 2024</h2>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/github/codeql-action/commit/d39d31e687223d841ef683f52467bd88e9b21c14"><code>d39d31e</code></a>
Merge pull request <a
href="https://redirect.github.com/github/codeql-action/issues/2262">#2262</a>
from github/update-v3.25.3-ac2f82a1f</li>
<li><a
href="https://github.com/github/codeql-action/commit/a7278252c70477c10a79034dae40a279c9a93c81"><code>a727825</code></a>
Move changenote to most recent section</li>
<li><a
href="https://github.com/github/codeql-action/commit/1efa8597b1a91824d046c53d4c10d77968957df1"><code>1efa859</code></a>
Update changelog for v3.25.3</li>
<li><a
href="https://github.com/github/codeql-action/commit/ac2f82a1ffdc5b61472756d5f098a9acf079c7bb"><code>ac2f82a</code></a>
Log warning if SIP is disabled and CLI version is &lt; 2.15.1 (<a
href="https://redirect.github.com/github/codeql-action/issues/2261">#2261</a>)</li>
<li><a
href="https://github.com/github/codeql-action/commit/0ad7791640e0365754b29776b989bb8a341a45e9"><code>0ad7791</code></a>
Merge pull request <a
href="https://redirect.github.com/github/codeql-action/issues/2247">#2247</a>
from github/update-bundle/codeql-bundle-v2.17.1</li>
<li><a
href="https://github.com/github/codeql-action/commit/79d9ee7f07f81f562eade2095cbd714baeda85d8"><code>79d9ee7</code></a>
Merge branch 'main' into update-bundle/codeql-bundle-v2.17.1</li>
<li><a
href="https://github.com/github/codeql-action/commit/dbf2b1706b768069fb1bb2dd2d8552be7a9e2a51"><code>dbf2b17</code></a>
Merge pull request <a
href="https://redirect.github.com/github/codeql-action/issues/2255">#2255</a>
from github/mergeback/v3.25.2-to-main-8f596b4a</li>
<li><a
href="https://github.com/github/codeql-action/commit/ff6a3c42a5824cbebd4b5610db68760f3896540a"><code>ff6a3c4</code></a>
Update checked-in dependencies</li>
<li><a
href="https://github.com/github/codeql-action/commit/619dc0c4b85a2de48427e29571874d67419d901f"><code>619dc0c</code></a>
Update changelog and version after v3.25.2</li>
<li><a
href="https://github.com/github/codeql-action/commit/39e1e6509e99d33f40a3508d4d56f24f29f37dcf"><code>39e1e65</code></a>
Add changelog note</li>
<li>Additional commits viewable in <a
href="https://github.com/github/codeql-action/compare/8f596b4ae3cb3c588a5c46780b86dd53fef16c52...d39d31e687223d841ef683f52467bd88e9b21c14">compare
view</a></li>
</ul>
</details>
<br />

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
15 months agoFix typos (#2169)
Tobias Stoeckmann [Sun, 5 May 2024 22:41:25 +0000 (00:41 +0200)] 
Fix typos (#2169)

Remove duplicated "of" in write-filter comments.

15 months agouu: Stop processing if lines are too long (#2168)
Tobias Stoeckmann [Sun, 5 May 2024 22:40:57 +0000 (00:40 +0200)] 
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.

15 months agolha: Fix integer truncation on 32 bit systems (#2161)
Tobias Stoeckmann [Sat, 4 May 2024 19:17:21 +0000 (21:17 +0200)] 
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.

15 months agoRename the test to match the filename, and avoid test failures on cas… (#2166)
Tim Kientzle [Sat, 4 May 2024 19:15:56 +0000 (12:15 -0700)] 
Rename the test to match the filename, and avoid test failures on cas… (#2166)

…e-insensitive filesystems

Resolves #2164

15 months agoFix typos (#2165)
Tobias Stoeckmann [Sat, 4 May 2024 17:58:25 +0000 (19:58 +0200)] 
Fix typos (#2165)

Typos found with codespell.

15 months agorpm: Test handling of huge header sizes (#2163)
Tim Kientzle [Fri, 3 May 2024 23:27:42 +0000 (16:27 -0700)] 
rpm: Test handling of huge header sizes (#2163)

This implements a test for the change in PR #2158

15 months agoFix out of boundary access in mktemp functions (#2160)
Tobias Stoeckmann [Fri, 3 May 2024 22:19:55 +0000 (00:19 +0200)] 
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.

15 months agozip: Improve bid for huge EOCDs (#2159)
Tobias Stoeckmann [Fri, 3 May 2024 22:18:34 +0000 (00:18 +0200)] 
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.

15 months agorpm: Calculate huge header sizes correctly (#2158)
Tobias Stoeckmann [Fri, 3 May 2024 21:41:35 +0000 (23:41 +0200)] 
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.

15 months agotests: setenv LANG to en_US.UTF-8 in bsdunzip test_I.c
Martin Matuska [Tue, 30 Apr 2024 09:25:26 +0000 (11:25 +0200)] 
tests: setenv LANG to en_US.UTF-8 in bsdunzip test_I.c

15 months agoarchive_string: Clean up strncat_from_utf8_to_utf8 (#2147)
Tim Kientzle [Tue, 30 Apr 2024 06:59:48 +0000 (23:59 -0700)] 
archive_string: Clean up strncat_from_utf8_to_utf8 (#2147)

Replace some tricky direct manipulation of string internals with simpler
and safer high-level string APIs.

15 months agolha: Do not allow negative file sizes (#2155)
Tobias Stoeckmann [Mon, 29 Apr 2024 20:06:30 +0000 (22:06 +0200)] 
lha: Do not allow negative file sizes (#2155)

Files sizes cannot be negative, so abort lha processing if archive
claims otherwise.

15 months agoarchive_match: Turn counter into flag (#2154)
Tobias Stoeckmann [Mon, 29 Apr 2024 20:05:44 +0000 (22:05 +0200)] 
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.

15 months agoarchive_match: check archive_read_support_format_raw() return value (#2153)
Tobias Stoeckmann [Mon, 29 Apr 2024 20:00:22 +0000 (22:00 +0200)] 
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.

15 months agofix: OOB in rar audio filter (#2149)
Wei-Cheng Pan [Sun, 28 Apr 2024 21:53:19 +0000 (06:53 +0900)] 
fix: OOB in rar audio filter (#2149)

This patch ensures that `src` won't move ahead of `dst`, so `src` will
not OOB. Similar situation like in a1cb648.

15 months agofix: OOB in rar delta filter (#2148)
Wei-Cheng Pan [Sun, 28 Apr 2024 21:50:22 +0000 (06:50 +0900)] 
fix: OOB in rar delta filter (#2148)

Ensure that `src` won't move ahead of `dst`, so `src` will not OOB.
Since `dst` won't move in this function, and we are only increasing `src`
position, this check should be enough. It should be safe to early return
because this function does not allocate resources.

15 months agoxar: Fix another infinite loop and expat error handling (#2150)
Tobias Stoeckmann [Sun, 28 Apr 2024 21:48:05 +0000 (23:48 +0200)] 
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

15 months agoLibarchive 3.7.5dev
Martin Matuska [Fri, 26 Apr 2024 10:07:47 +0000 (12:07 +0200)] 
Libarchive 3.7.5dev

15 months agoRelease 3.7.4 v3.7.4
Martin Matuska [Fri, 26 Apr 2024 09:22:15 +0000 (11:22 +0200)] 
Release 3.7.4

15 months agobsdtar: Fix error handling around strtol() usages (#2110)
Tim Kientzle [Thu, 25 Apr 2024 09:39:22 +0000 (02:39 -0700)] 
bsdtar: Fix error handling around strtol() usages (#2110)

The code here had a couple of bad code patterns that seem to have been
copied throughout:
* Checking errno after strtol() -- Standard C doesn't seem to actually
require this, so we shouldn't rely on it
* Casting the result of strtol() directly to `int`. This loses
information prematurely.

Instead, I've added `l` as a temporary of type `long`, use that to hold
the result of `strtol()` until it can be checked. I've also removed the
`errno` tests in favor of checking the end pointer value.

The limit for --strip-components has been raised to 100 000.

15 months agoFix typos (#2143)
Tobias Stoeckmann [Thu, 25 Apr 2024 09:22:45 +0000 (09:22 +0000)] 
Fix typos (#2143)

Fix typos in comments, documentation, and error messages.

15 months agowarc: Check realloc return value (#2144)
Tobias Stoeckmann [Thu, 25 Apr 2024 09:20:23 +0000 (09:20 +0000)] 
warc: Check realloc return value (#2144)

Since realloc could fail, check its return value and set a proper error
message.

15 months agozip: Fix out of boundary access (#2145)
Tobias Stoeckmann [Thu, 25 Apr 2024 09:18:30 +0000 (09:18 +0000)] 
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`.

15 months agoCI: bump the all-actions group with 3 updates (#2140)
dependabot[bot] [Tue, 23 Apr 2024 14:41:54 +0000 (16:41 +0200)] 
CI: bump the all-actions group with 3 updates (#2140)

Updates actions/checkout from 4.1.2 to 4.1.3
Updates actions/upload-artifact from 4.3.1 to 4.3.3
Updates github/codeql-action from 3.24.8 to 3.25.2

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
15 months agoCI: add "CI" prefix to dependabot commit messages
Martin Matuska [Tue, 23 Apr 2024 14:32:16 +0000 (16:32 +0200)] 
CI: add "CI" prefix to dependabot commit messages

15 months agozstd: Implement core detection on Windows
Martin Matuska [Tue, 23 Apr 2024 12:59:27 +0000 (14:59 +0200)] 
zstd: Implement core detection on Windows

Fixes #2071

Co-authored-by: Mostyn Bramley-Moore <mostyn@antipode.se>
15 months agozstd: Implement core detection (#2083)
Dag-Erling Smørgrav [Mon, 4 Mar 2024 10:37:14 +0000 (11:37 +0100)] 
zstd: Implement core detection (#2083)

The bsdtar manual page claims that setting zstd:threads to 0 tells zstd
to use as many threads as there are cores in the system, but it actually
disables multi-threading.  Replace 0 with the number of configured
processors.

While here, add a previously missing overflow check.

Co-authored-by: Martin Matuska <martin@matuska.de>
15 months agoCI: add libxml2 to MacOS test build
Martin Matuska [Tue, 23 Apr 2024 09:51:53 +0000 (11:51 +0200)] 
CI: add libxml2 to MacOS test build

15 months agoxar: Avoid infinite link loop (#2123)
Tobias Stoeckmann [Wed, 10 Apr 2024 20:59:40 +0000 (22:59 +0200)] 
xar: Avoid infinite link loop (#2123)

A file may have only one link target at a time. Otherwise the internal
link structure could loop. Besides, a hard link realistically can only
link to one file, not multiple ones.

Consider such an archive invalid.

Co-authored-by: Martin Matuska <martin@matuska.de>
15 months agorar: Avoid overwriting data at "end" of circular window buffer (#2124)
Duncan Horn [Tue, 23 Apr 2024 06:25:39 +0000 (23:25 -0700)] 
rar: Avoid overwriting data at "end" of circular window buffer (#2124)

fix "File CRC Error" when extracting specific rar4 archives

Fixes #1794

15 months agounzip: explicitly set en_US.UTF-8 locale in test_I.c
Martin Matuska [Tue, 23 Apr 2024 05:45:50 +0000 (07:45 +0200)] 
unzip: explicitly set en_US.UTF-8 locale in test_I.c

15 months agofix: OOB in rar e8 filter (#2135)
Wei-Cheng Pan [Sun, 21 Apr 2024 16:55:41 +0000 (01:55 +0900)] 
fix: OOB in rar e8 filter (#2135)

This patch fixes an out-of-bound error in rar e8 filter.

15 months agoUpdate AppleDouble support for directories (#2108)
Martin Matuška [Sun, 21 Apr 2024 03:23:22 +0000 (05:23 +0200)] 
Update AppleDouble support for directories (#2108)

This is a clone of the reverted pull request #2100. Due to the latest
circumstances we should require a more deep review of each new PR.

---------

Co-authored-by: Justin Vreeland <j_vreeland@apple.com>
15 months ago7zip: Limit amount of properties (#2131)
Tobias Stoeckmann [Sat, 20 Apr 2024 22:39:38 +0000 (22:39 +0000)] 
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.

15 months ago[Windows] Ignore more directories generated by Visual Studio (#2133)
Tobias Stoeckmann [Fri, 19 Apr 2024 15:12:59 +0000 (15:12 +0000)] 
[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.

15 months agotests: fix null format string error in test_compat_lzip.c
Martin Matuska [Wed, 17 Apr 2024 07:15:35 +0000 (09:15 +0200)] 
tests: fix null format string error in test_compat_lzip.c

15 months agoChange CMAKE_BUILD_TYPE comparison to be case-insensitive (#2130)
evan-swinney [Wed, 17 Apr 2024 03:51:30 +0000 (22:51 -0500)] 
Change CMAKE_BUILD_TYPE comparison to be case-insensitive (#2130)

Currently the `CMAKE_BUILD_TYPE` is being compared in a case-sensitive
way. It seems current CMake documentation [suggests treating this in a
case-insensitive manner
now-a-days](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#case-sensitivity).

This being case-sensitive creates needless complexities in other
projects if they compile their own project with `cmake
-DCMAKE_BUILD_TYPE=release ..`, etc. In this specific case, libarchive
has a fatal error due to the lowercase `release`.

I'd honestly like to remove these comparisons entirely; as I'm not sure
if they're really needed or not if `libarchive` is only using the
Makefile or Ninja generators with CMake.

This PR changes the `CMAKE_BUILD_TYPE` comparison to be
case-insensitive, and leaves the rest alone.

This should also fix the following issue(s):
* https://github.com/libarchive/libarchive/issues/1792

15 months agoNever allow empty passwords (#2116)
Tobias Stoeckmann [Sat, 13 Apr 2024 05:44:51 +0000 (05:44 +0000)] 
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.

15 months agoImprove newline handling on Windows (#2115)
Tobias Stoeckmann [Sat, 13 Apr 2024 05:40:02 +0000 (05:40 +0000)] 
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.

15 months ago[Windows] Ignore files generated by Visual Studio with CMake (#2120)
Tobias Stoeckmann [Sat, 13 Apr 2024 05:26:53 +0000 (05:26 +0000)] 
[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.

15 months agotools: Fix stack overflow with many arguments (#2122)
Tobias Stoeckmann [Sat, 13 Apr 2024 05:15:53 +0000 (05:15 +0000)] 
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.

15 months agoPrevent usage of uninitialized variable in `__archive_mkstemp` (#2121)
Tobias Stoeckmann [Sat, 13 Apr 2024 05:14:59 +0000 (05:14 +0000)] 
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

15 months agoFix unused-function warning. (#2114)
Adrian Iain Lam [Sat, 13 Apr 2024 05:13:42 +0000 (06:13 +0100)] 
Fix unused-function warning. (#2114)

`string_to_size` is only used in a code block conditionally compiled
with `#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream`. If this block is not
compiled, GCC raises a warning with -Wunused-function.

15 months agoFix version string (#2118)
Tim Kientzle [Sat, 13 Apr 2024 00:28:25 +0000 (17:28 -0700)] 
Fix version string (#2118)

Looks like the recent version number update from 3.7.3 -> 3.7.4dev
missed a spot...

15 months agoconfigure.ac: fix bashism in dead code removal check (#2117)
Sam James [Wed, 10 Apr 2024 03:15:17 +0000 (04:15 +0100)] 
configure.ac: fix bashism in dead code removal check (#2117)

configure scripts need to be runnable with a POSIX-compliant /bin/sh.

On many (but not all!) systems, /bin/sh is provided by Bash, so errors
like this aren't spotted. Notably Debian defaults to /bin/sh provided by
dash which doesn't tolerate such bashisms as '=='.

This retains compatibility with bash.

Signed-off-by: Sam James <sam@gentoo.org>
15 months agoLibarchive 3.7.4dev
Martin Matuska [Mon, 8 Apr 2024 10:17:17 +0000 (12:17 +0200)] 
Libarchive 3.7.4dev

15 months agoRelease 3.7.3 v3.7.3
Martin Matuska [Sun, 7 Apr 2024 22:11:03 +0000 (00:11 +0200)] 
Release 3.7.3

15 months agobuild: use standard HAVE_ pattern for ZSTD compression check (#2111)
Tim Kientzle [Sun, 7 Apr 2024 21:44:37 +0000 (14:44 -0700)] 
build: use standard HAVE_ pattern for ZSTD compression check (#2111)

Follow-on to #1649: this just changes the name of the preprocessor macro
to use the standard pattern HAVE_<function name>

In particular: newer ZSTD implementations have a growing variety of
compression functions; the standard pattern will make it easier to
select among those someday.

15 months agocontrib/untar.c: cleanup (#2112)
Tim Kientzle [Sun, 7 Apr 2024 21:43:05 +0000 (14:43 -0700)] 
contrib/untar.c: cleanup (#2112)

This reworks PR #1613 (commit a902fcd4), addressing the same issues as that
earlier PR, but in a simpler and more portable fashion.

Co-authored-by: Martin Matuška <martin@matuska.org>
16 months agoRevert "zip: update AppleDouble support for directories (#2100)"
Martin Matuska [Wed, 3 Apr 2024 09:15:22 +0000 (11:15 +0200)] 
Revert "zip: update AppleDouble support for directories (#2100)"

This reverts commit 390d83012fdba8c8db7fc9915338805882b0597a.
PR reopened back for review.

16 months agozip: update AppleDouble support for directories (#2100)
jvreelanda [Mon, 1 Apr 2024 22:21:12 +0000 (15:21 -0700)] 
zip: update AppleDouble support for directories (#2100)

16 months agorar5: don't continue if the last block produced no data (#2105)
Duncan Horn [Mon, 1 Apr 2024 18:13:19 +0000 (11:13 -0700)] 
rar5: don't continue if the last block produced no data (#2105)

There appear to be RAR5 archives out in the wild that have blocks at the
end of files that don't produce any data. The code in libarchive has an
infinite loop that won't break until it processes a block that produces
data, which will end up reading past the end of the file if the last
block in the file produces no data.

16 months agoci: use liblzma 1.5.5 in MSVC build until fix from upstream (#2105)
Martin Matuska [Mon, 1 Apr 2024 17:41:19 +0000 (19:41 +0200)] 
ci: use liblzma 1.5.5 in MSVC build until fix from upstream (#2105)

Signed-off-by: Duncan Horn
16 months agocmake: look for libxml2 only if HAVE_ICONV is set (#2105)
Martin Matuska [Mon, 1 Apr 2024 17:40:34 +0000 (19:40 +0200)] 
cmake: look for libxml2 only if HAVE_ICONV is set (#2105)

Signed-off-by: Duncan Horn