0
0
mirror of https://github.com/libarchive/libarchive.git synced 2026-01-18 17:11:25 +01:00

7023 Commits

Author SHA1 Message Date
Tim Kientzle
a474bab7e3 Merge pull request #2688 from stoeckmann/entry_off32
Ignore sizes which do not fit into off_t
2025-06-28 14:11:17 -07:00
Will Fancher
489d0b8e2f clear_nochange_fflags: Use linux FS flags 2025-06-27 19:24:34 -04:00
Tobias Stoeckmann
1e4b84ed30 Ignore sizes which do not fit into off_t
It is possible to handle entries and files with sizes which do not fit
into off_t of the current system (Windows always has 32 bit off_t and
32 bit systems without large file support also have 32 bit off_t).

Set sizes to 0 in such cases. The fstat system call would return -1 and
set errno to EOVERFLOW, but that's not how archive_entry_set_size acts.
It would simply ignore negative values and set the size to 0.

Actual callers of archive_entry_stat from foreign projects seem to not
even check for NULL return values, so let's try to handle such cases as
nice as possible.

Affects mtree's checkfs option as well (Windows only, 32 bit systems
would simply fail in fstat/stat).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-27 17:06:14 +02:00
Dustin Howett
50d44b4202 win32: shim wopen, and make both open/wopen use _s "secure" variant
The new `__la_wopen` wrapper is a copy of `__la_open` that
expects--rather than converts--a wcs parameter.

The `sopen` variants are offered as "more secure" variants of `open` and
`wopen`; I cannot vouch for their security, but some build systems are
strict about the use of "banned insecure APIs".

I've confirmed that `_wsopen_s` and `_open_s` are present in the Windows
Vista SDK.

I did not confirm that they are available in the Windows XP Platform
SDK, in part because in e61afbd463 (2016!) Tim says:

> I'd like to completely remove support for WinXP and earlier.
2025-06-26 10:56:33 -07:00
Rose
b1b3709cae Handle possible errors from system calls
dup, open, etc, can fail and we should not assume they do not.
2025-06-20 17:35:54 -04:00
Tim Kientzle
ffde04f272 Merge pull request #2672 from AZero13/ferror
Fix error checking in writing files
2025-06-20 14:33:45 -07:00
Rose
fd4ecc0146 Fix error checking in writing files
For write, 0 may not mean an error at all. We need to instead check for the length not being the same.

With fwrite, because 0 could mean an error, but not always. We must check that we wrote the entire file!

Note that unlike write, fwrite's description according to POSIX does not mention returning a negative type at all. Nor does it say you can retry unlike write.

Finally, with write, we need to check less than 0, not 0, as 0 is a valid return and does not mean an error.
2025-06-20 13:55:57 -04:00
Tim Kientzle
a218a52dbb Merge pull request #2678 from mostynb/zstd_filter_checksum
Enable Zstandard's checksum feature in the zstd write filter
2025-06-20 09:32:51 -07:00
Mostyn Bramley-Moore
0de62cbda8 Enable Zstandard's checksum feature in the zstd write filter
Note that this is not enabled when writing .zip or .7z archive formats,
because they already use their own checksums.

Implements #2675.
2025-06-20 14:42:40 +02:00
Tim Kientzle
e4978e2edd Merge pull request #2677 from AZero13/fwrite
Change error message from "fwrite function failed" to "write function failed"
2025-06-19 16:12:26 -07:00
Rose
40a89c7379 Change error message from "fwrite function failed" to "write function failed"
We are checking the return value from write, not fwrite, so this message is wrong.
2025-06-19 14:44:43 -04:00
Tim Kientzle
6a252c84a2 Merge pull request #2676 from danyeaw/fix-pkgconf-path
Fix .pc location when CMAKE_INSTALL_LIBDIR not set
2025-06-19 08:20:43 -07:00
Dan Yeaw
4984c652db Fix .pc location when CMAKE_INSTALL_LIBDIR not set 2025-06-18 21:27:04 -04:00
Hemant
664a20b6c7 Error related to restrict keyword supressed for older vs compiler 2025-06-18 14:05:23 -05:00
Hemant
b7066d4a6b Error related to restrict keyword supressed for older vs compiler 2025-06-18 13:51:00 -05:00
Martin Matuška
6effe2ec6b Merge pull request #2659 from stoeckmann/chld
Improve filter process handling
2025-06-12 10:59:43 +02:00
Martin Matuška
251f7e839c Merge pull request #2669 from benoit-pierre/pr/minor_test_related_tweaks
minor test related tweaks
2025-06-12 10:57:17 +02:00
Martin Matuška
47bdf82489 Merge pull request #2663 from stoeckmann/filename_errpath
open_filename: Free memory on error paths
2025-06-12 10:56:32 +02:00
Martin Matuška
c3be70e071 Merge pull request #2665 from stoeckmann/read_data_sparse
archive_read_data: Handle sparse holes at end of file correctly
2025-06-12 10:54:08 +02:00
Martin Matuška
9bdc5b82f7 Merge pull request #2668 from stoeckmann/7z_oob
7zip: Fix out of boundary access
2025-06-12 10:51:45 +02:00
Raman Shyshniou
475423a154 archive_cryptor_private.h: check message digest functions are enabled for windows 2025-06-12 00:22:47 +00:00
Benoit Pierre
864c904442 test_utils: factorize canProg implementations 2025-06-08 00:05:58 +02:00
Benoit Pierre
dcf5475661 test_utils: fix canRunCommand implementation
Do not unconditionally cache the result of the first call (and
reused it for subsequent calls). Thankfully, the function is
only called once.
2025-06-08 00:05:34 +02:00
Tobias Stoeckmann
90c1e32a0d open_filename: Free memory on error paths
If opening a filename fails, make sure that allocated memory which is
not inserted into any remaining structure is freed.

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

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-05 22:17:56 +02:00
Tobias Stoeckmann
c0691458a0 7zip: Fix out ouf boundary read in ELF detection
Make sure that the string table size is not smaller than 6 (and also
not larger than SIZE_MAX for better 32 bit support).

Such small values would lead to a large loop limit which either leads to
a crash or wrong detection of a ".data" string in possibly uninitialized
memory.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-05 21:38:43 +02:00
Tobias Stoeckmann
75ef803092 7zip: Increase minimum ELF header length
The 64 bit format requires at least 63 bytes, so increase this limit.
Such small binaries most likely don't contain 7zip data anyway.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-05 21:36:23 +02:00
Tim Kientzle
0931c12b7e Merge pull request #2662 from stoeckmann/set_format_strcpy
archive_read_set_format: Remove strcpy calls
2025-06-04 05:58:32 -07:00
Tobias Stoeckmann
b1839a20e5 archive_read: Handle sparse holes at end of file
If a sparse hole is located at the end of an entry, then the tar
parser returns ARCHIVE_EOF while updating the offset where 0 bytes of
data will follow.

If archive_read_data encounters such an ARCHIVE_EOF return value, it
has to recheck if the offsets (data offset and output offset) still
match. If they do not match, it has to keep filling 0 bytes.

This changes assumes that it's okay to call archive_read_data_block
again after an EOF. As far as I understood the parsers so far, this
should be okay, since it's always ARCHIVE_EOF afterwards.

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

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 22:01:15 +02:00
Tobias Stoeckmann
f3949062ed rar: Do not forcefully set offset to unpacked size
If an entry reaches its end of file, the offset is not necessarily
the same as unp_size. This is especially true for links which have
a "0 size body" even though the unpacked size is not 0.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 21:59:05 +02:00
Tobias Stoeckmann
cdb45d71b2 warc: Ignore separator when reaching end of entry
When _warc_read encounters end of entry, it adds 4 bytes to the last
offset for \r\n\r\n separator, which is never written. Ignore these
bytes since they are not part of the returned entry.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 21:57:42 +02:00
Tobias Stoeckmann
fa85c7eaae xar: End with entry offset, not archive offset
If xar_read_data has no further data, set offset to end of entry,
not to total size of parsed archive so far.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 21:57:05 +02:00
Federico Giovanardi
aa69d34311 Fix a memory leak if write callback error early 2025-06-03 18:24:35 +02:00
Tobias Stoeckmann
5a60d8cda4 archive_read_set_format: Remove strcpy calls
The string constants can be used directly for comparison, which makes
this code robust against future changes which could lead to names being
longer than str could hold on stack.

Also removes around 100 bytes from compiled library (with gcc 15).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 17:43:27 +02:00
Tobias Stoeckmann
ac66e0bc42 Skip zlib tests if support is missing
If zlib is not supported, do not run tests to avoid false positives.

Also adjust tests to support latest gzip versions (1.10+) which store
less information for improved reproducibility. The gzip binary is
used as a fallback if zlib is not available.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 17:27:48 +02:00
Tobias Stoeckmann
f2c3c790ff Skip lzma test if support is missing
If lzma is not supported, do not run tests to avoid false positives.

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

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 17:27:48 +02:00
Tobias Stoeckmann
b7e1c617cb Skip KOI8 conversion test if support is missing
If a unix system has no iconv support, the best effort function will
be unable to convert KOI8 to UTF-8. Skip the test if such support is
missing.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 17:27:48 +02:00
Tobias Stoeckmann
c40a3887ab unzip: Pass test if encryption support is missing
If no encryption support exists, the -P option will always fail.
"Skip" the test by making sure that there really is no encryption
support according to libarchive functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 17:27:48 +02:00
Tobias Stoeckmann
9836e7e2fe zip: Better detect no encryption support
Some functions might return -1 in case of library error. Use an
own return value if a stub function was used for better error
messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 17:27:48 +02:00
Tim Kientzle
a8f93f2480 Merge pull request #2660 from kevans91/ke/fix-fortify
libarchive/test: fix build when memcpy() is a macro
2025-06-03 06:02:09 -07:00
Kyle Evans
b76c4042ae libarchive/test: fix build when memcpy() is a macro
After importing the latest libarchive into FreeBSD, Shawn Webb @
HardenedBSD noted that the test build is broken when FORTIFY_SOURCE=2
while building the base system.  Braced initializer lists are a special
case that need some extra fun parentheses when we're dealing with the
preprocessor.

While it's not a particularly common setup, the extra parentheses don't
really hurt readability all that much so it's worth fixing for wider
compatibility.

Fixes: libarchive/libarchive#2657
2025-06-02 21:46:28 -05:00
Tobias Stoeckmann
36bac92cd2 tools: Enforce default handling of SIGCHLD
Ignoring SIGCHLD gets passed to child processes. Doing that has
influence on waitpid, namely that zombie processes won't be
created. This means that a status can never be read.

We can't enforce this in library, but libarchive's tools can be
protected against this by enforcing default handling.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-02 23:29:49 +02:00
Tobias Stoeckmann
2764062e65 Unify reader and writer filter process handling
Use pid_t since waitpid returns a pid_t. Also check for a negative
return value in writer as well to avoid reading the possibly
unitialized status value.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-02 23:28:26 +02:00
Tobias Stoeckmann
13700e1fb8 windows: close child process handle only once
Calling CloseHandle multiple times for the same handle can lead to
exceptions while debugging according to documentation.

Mimic the waitpid handling for success cases to behave more like the
Unix version which would "reap the zombie".

Doing this for an unsuccessful call is off, but the loop is never
entered again, so I guess it's okay and worth it to reduce the amount
of Windows specific definitions in source files.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-02 23:23:05 +02:00
Tobias Stoeckmann
d7d1d19bb6 windows: Preserve GetExitCodeProcess error
If the waitpid version for Windows fails, preserve the error code and
avoid overwriting it with a possible CloseHandle error.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-02 23:21:26 +02:00
Tim Kientzle
0f9a06d6ab Merge pull request #2655 from mmatuska/fix/setclocale
test_utils/test_main.c: satisfy -Wstrict-prototypes
2025-06-01 16:04:49 -07:00
Martin Matuska
1311a438a3 test_utils/test_main.c: satisfy -Wstrict-prototypes 2025-06-01 23:35:05 +02:00
Martin Matuška
70978468e9 Merge pull request #2627 from heirecka/do-not-hard-code-pkg-config
Use PKG_CONFIG instead of hard-coded pkg-config
2025-05-31 21:40:04 +02:00
Martin Matuška
c7b7bd7c0e Merge pull request #2643 from stoeckmann/tar_pax_sparse
tar: Handle extra bytes after sparse entries
2025-05-31 21:31:14 +02:00
Tim Kientzle
8d074302ac Merge pull request #2652 from stoeckmann/wstring_ensure
Check archive_wstring_ensure return value
2025-05-31 07:16:07 -07:00
Tobias Stoeckmann
e1ca935c00 Always check archive_wstring_ensure return value
Memory allocation might fail, so check if it was successful.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-31 11:37:02 +02:00