1
0
mirror of https://git.tukaani.org/xz.git synced 2026-03-28 21:01:22 +00:00

1489 Commits

Author SHA1 Message Date
Lasse Collin
0ac3b93387
xz: Prevent an integer overflow in --files and --files0
This requires a filename (or something that pretends to be a filename)
of at least 2 GiB on a 32-bit platform, and that realloc() to
SIZE_MAX / 2 + 1 bytes has succeeded.

Fixes: https://github.com/tukaani-project/xz/pull/218
2026-03-27 18:13:26 +02:00
Lasse Collin
2faa141bdb
tuklib_integer: Fix inefficient aligned_writeXXne
The __builtin_assume_aligned was applied to the wrong argument which
made aligned writes worse on strict-align archs.

Aligned writes aren't used in liblzma, so this bug didn't matter in
this package; tuklib_integer.h is meant to be usable elsewhere too.
2026-03-27 18:13:26 +02:00
Collin Funk
3a78a82bd3
xz: Don't fsync directories on QNX
On QNX calling fsync on a directory fails with EINVAL. This causes the
following test failure:

    $ cat tests/test_suffix.sh.log
    /data/home/root/xz-5.8.2/src/xz/.libs/lt-xz: suffix_temp: Synchronizing the directory of the file failed: Invalid argument
    Failed to decompress a file with a suffix set in raw format
    FAIL test_suffix.sh (exit status: 1)

Closes: https://github.com/tukaani-project/xz/pull/216
2026-03-27 18:13:21 +02:00
Lasse Collin
5553509f1a
liblzma: Fix a copy-paste error in commented-out code
Fixes: https://github.com/dotnet/runtime/pull/124003#discussion_r2841960994
Fixes: 96b663f67c0e ("liblzma: Refactor CRC comments.")
2026-02-25 17:32:13 +02:00
Lasse Collin
4e76651dba
Fix typos and grammar in comments and docs
Fixes: https://github.com/dotnet/runtime/pull/124003#discussion_r2789354505
Fixes: https://github.com/dotnet/runtime/pull/124003#discussion_r2789354515
Fixes: https://github.com/dotnet/runtime/pull/124003#discussion_r2820960196
2026-02-25 17:32:13 +02:00
Lasse Collin
cd8a6231d0
tuklib_open_stdxxx: Fix a typo in macro name
It doesn't matter in this package, but it's good to fix it still.

Fixes: https://github.com/dotnet/runtime/pull/124003#discussion_r2782313660
2026-02-25 17:32:13 +02:00
Radek Zikmund
b0f3b64a25
liblzma/MSVC: Add a cast to fix a warning (C4057) with __cpuid()
__cpuid from MSVC (and also the old Intel ICC) use int[], while
__get_cpuid from <cpuid.h> in GCC and Clang use unsigned int[].
Adding a cast is the simplest fix.

Link: https://github.com/tukaani-project/xz/pull/208
2026-02-25 17:32:13 +02:00
Lasse Collin
d6bdb446f8
liblzma: Add the "License" property to liblzma.pc
The "License" property is a pkgconf extension. See pc(5).
pkg-config 0.29.2 (2017) ignores unrecognized properties so this
commit shouldn't create compatibility issues.

pkgconf provides bomtool which uses the "License" property to generate
a software bill of materials. In pkgconf.git there is spdxtool for the
same task but with different output format.

The pkgconf extensions "Copyright" and "Maintainer" would also be
used by bomtool and spdxtool, but I don't want to add those properties
at least for now.

Co-authored-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
Closes: https://github.com/tukaani-project/xz/pull/178
2026-01-25 13:44:52 +02:00
Lasse Collin
b80b6343a4
liblzma: Don't try to use x86-64 inline asm on ARM64EC
Reported-by: Chase Knowlden
Fixes: https://github.com/tukaani-project/xz/issues/206
2026-01-25 12:16:39 +02:00
Lasse Collin
3d078b52ad
Bump version and soname for 5.8.2 2025-12-17 13:36:42 +02:00
Lasse Collin
b8af36920b
xz: Never translate "Failed to enable the sandbox"
This was already the case in practice because I had forgotten to list
src/xz/sandbox.c in po/POTFILES.in. However, it seems better to never
translate this particular error message. It should almost never occur
and if it does, an untranslated message is should make it easier to
find bug reports about it.
2025-12-09 17:18:23 +02:00
Lasse Collin
338f952c00
xz: Silence clang -Wunreachable-code-break
Fixes: a165d7df1964 ("xz: Add a new --filters-help option.")
2025-12-09 17:18:22 +02:00
Lasse Collin
723cee44d0
liblzma: Remove unwanted semicolons
These didn't affect control flow.
2025-12-09 17:18:22 +02:00
Lasse Collin
a3c6cb0911
xz/Windows: Add a missing #include to fix the build with clang-cl
Fixes: https://github.com/tukaani-project/xz/issues/18#issuecomment-1986829734
Fixes: https://github.com/tukaani-project/xz/issues/18#issuecomment-3577456136
2025-12-09 17:18:22 +02:00
Lasse Collin
c410ccc625
xz: Check return value of sigaction() before calling raise()
Fixes: Coverity CID 456022
2025-12-09 17:18:21 +02:00
Lasse Collin
6cc2da0a4b
liblzma: Refactor a loop in lzma_filters_copy()
Arguably it's nicer if i doesn't wrap around when the loop terminates.

Fixes: Coverity CID 464589
Fixes: 6d118a0b9def ("Add lzma_filters_copy().")
2025-12-09 17:18:21 +02:00
Lasse Collin
90b67853d5
liblzma: Silence two Coverity warnings
lzma_lzma_decoder_memusage() returns UINT64_MAX if lc/lp/pb aren't
valid. alone_decoder.c and lzip_decoder.c didn't check the return
value because in both it is known that lc/lp/pb are valid. Make them
call the _nocheck() variant instead which skips the validation (it
already existed for LZMA2's internal use).

Fixes: Coverity CID 464658
Fixes: Coverity CID 897069
2025-12-09 17:18:21 +02:00
Lasse Collin
be365b7010
liblzma: Fix a harmless read of shared variable without mutex
The partial_update_mode enumeration had three states, _DISABLED,
_START, and _ENABLED. Main thread changed it from _DISABLED to _START
while holding a mutex. Once set to _START, worker thread changed it
to _ENABLED without a mutex. Later main thread read it without a mutex,
so it could see either _START or _ENABLED. However, it made no
difference because the main thread checked for != _DISABLED, so
it didn't matter if it saw _START or _ENABLED.

Nevertheless, such things must not be done. It's clear it was a mistake
because there were two comments that directly contradicted each
other about how the variable was accessed.

Split the enumeration into two booleans:

  - partial_update_enabled: A worker thread locks the mutex to read
    this variable and the main thread locks the mutex to change the
    value. Because only the main thread modifies the variable, the
    main thread can read the value without locking the mutex.
    This variable replaces the _DISABLED -> _START transition.

  - partial_update_started is for worker thread's internal use and thus
    needs no mutex. This replaces the _START -> _ENABLED transition.

Fixes: Coverity CID 456025
Fixes: bd93b776c1bd ("liblzma: Fix a deadlock in threaded decoder.")
2025-12-09 17:18:21 +02:00
Lasse Collin
8bb516887c
Landlock: Add missing #ifdefs
The build was broken on distros that have an old <sys/landlock.h>.

Fixes: 2b2652e914b1 ("Landlock: Workaround a bug in RHEL 9 kernel")
2025-11-23 20:39:28 +02:00
Lasse Collin
2b2652e914
Landlock: Workaround a bug in RHEL 9 kernel
If one runs xz 5.8.0 or 5.8.1 from some other distribution in a container
on RHEL 9, xz will fail with the message "Failed to enable the sandbox".

RHEL 9 kernel since 5.14.0-603.el9 (2025-07-30) claims to support
Landlock ABI version 6, but it lacks support for LANDLOCK_SCOPE_SIGNAL.
The issue is still present in 5.14.0-643.el9 (2025-11-22). Red Hat is
aware of the issue, but I don't know when it will be fixed.

The sandbox is meant to be transparent to users, thus there isn't and
won't be a command line option to disable it. Instead, add a workaround
to keep xz working on the buggy RHEL 9 kernels.

Reported-by: Richard W.M. Jones
Thanks-to: Pavel Raiskup
Tested-by: Orgad Shaneh
Tested-by: Richard W.M. Jones
Fixes: https://github.com/tukaani-project/xz/issues/199
Link: https://issues.redhat.com/browse/RHEL-125143
Link: https://bugzilla.redhat.com/show_bug.cgi?id=2407105
Link: https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/message/65BDSY56R5ZJRTUC4B6CIVCVLY4LG4ME/
2025-11-23 20:13:49 +02:00
Lasse Collin
ee75c76958
Landlock: Cache the ABI version
In xz it can avoid up to two syscalls that query the ABI version.
2025-11-23 20:13:37 +02:00
Lasse Collin
211cde0923
mythread.h: Fix the build on Emscripten when threading is disabled
To make a non-threaded liblzma-only build work with WASI SDK, <signal.h>
and mythread_sigmask() were omitted from mythread.h in the commit
81db3b889830. This broke non-threaded full build with Emscripten because
src/xz/signals.c needs mythread_sigmask() (liblzma-only build was fine).

If __wasm__ is defined, omit <signal.h> and mythread_sigmask() in
non-threaded builds only when __EMSCRIPTEN__ isn't defined.

Reported-by: Marcus Tillmanns
Thanks-to: ChanTsune
Fixes: https://github.com/tukaani-project/xz/issues/161
Fixes: 81db3b889830 ("mythread.h: Disable signal functions in builds targeting Wasm + WASI.")
2025-11-03 14:48:15 +02:00
Lasse Collin
68d1591187
xz: Silence a compiler warning when signals_block_count is unused
Move the static variable signals_block_count to the #ifndef block
that already has the functions that need the variable.
2025-11-02 19:40:55 +02:00
Lasse Collin
beca015891
xz: Silence a warning from Clang on glibc systems
Fixes: e8838b2f5922 ("xz: Look at resource limits when determining the default memlimit")
2025-11-02 17:45:20 +02:00
Lasse Collin
ef67e051d7
liblzma: Fix build on old Linux/glibc on ARM64
getauxval() can be available even if HWCAP_CRC32 isn't #defined, so
both have to be checked. HWCAP_CRC32 was added in glibc 2.24 (2016).

Fixes: https://github.com/tukaani-project/xz/issues/190
2025-10-31 19:21:48 +02:00
Kirill A. Korinsky
e8838b2f59
xz: Look at resource limits when determining the default memlimit
When no memory usage limits have been set by the user, the default
for multithreaded mode has been 1/4 of total RAM. If this limit is
too high and memory allocation fails, liblzma (and xz) fail. Perhaps
liblzma should handle it better by reducing the number of threads
and continuing with the amount of memory it can allocate, but currently
that isn't the case.

If resource limits were set to about 1/4 of RAM or lower, then xz
could fail for the above reason. This commit makes xz look at
RLIMIT_DATA, RLIMIT_AS, and RLIMIT_VMEM when they are available,
and set the limit 64 MiB below the lowest of those limits. This is
more or less a hack just like the 1/4-of-RAM method is, but this is
simple and quick to implement.

On Linux, there are other limits like cgroup v2 memory.max which
can still make xz fail. The same is likely possible with FreeBSD's
rctl(8).

Co-authored-by: Lasse Collin <lasse.collin@tukaani.org>
Thanks-to: Fangrui Song
Fixes: https://github.com/tukaani-project/xz/issues/195
Closes: https://github.com/tukaani-project/xz/pull/196
2025-10-31 12:43:37 +02:00
Lakshmi-Surekha
eaa150df98
xz: Don't fsync() directories on AIX
It fails with EBADF.

Fixes: https://github.com/tukaani-project/xz/issues/188
Closes: https://github.com/tukaani-project/xz/pull/189
2025-09-29 19:25:11 +03:00
Lasse Collin
61b114e92f
liblzma: Document that lzma_allocator.free(opaque, NULL) is possible
It feels better to fix the docs than change the code because this
way newly-written applications will be forced to be compatible with
the lzma_allocator behavior of old liblzma versions. It can matter
if someone builds the application against an older liblzma version.

Fixes: https://github.com/tukaani-project/xz/issues/183
2025-09-29 18:37:19 +03:00
Lasse Collin
e3ba73034a
liblzma: validate_map.sh: Catch some unlikely errors 2025-09-29 17:50:45 +03:00
Lasse Collin
4fc6208abe
Scripts: Add shellcheck directives to silence warnings
Set also shell because the xz*.in files start with '#!@POSIX_SHELL@'.

SC1003 and SC2016 are only info messages, not warnings. Several other
shellcheck info messages remain. They are safe to ignore, but I didn't
want to disable them now.

Partially-fixes: https://github.com/tukaani-project/xz/issues/174
2025-09-29 17:50:45 +03:00
Lasse Collin
7844aff1a8
Scripts: Silence two shellcheck warnings 2025-09-29 17:50:39 +03:00
Lasse Collin
d660fe5d56
liblzma: Fix grammar in API docs
Fixes: a27920002dbc ("liblzma: Add generic support for input seeking (LZMA_SEEK).")
2025-05-23 12:28:17 +03:00
Lasse Collin
377be0ea7a
Build: With symbol versioning, try to pass --undefined-version to linker
Fixes: https://github.com/tukaani-project/xz/issues/180
Fixes: https://bugs.gentoo.org/956119
2025-05-21 16:07:01 +03:00
Guillaume Outters
5cc2e479eb
xz, xzdec: Capsicum sandbox: Fix incorrect use of cap_rights_clear()
cap_rights_clear() with no additional arguments acts as a no-op, so
instead of removing all capability rights from STDIN_FILENO, the same
rights were allowed for STDIN_FILENO as were allowed for src_fd.

Fixes: a0eecc235d3b ("xz: Make Capsicum sandbox more strict with stdin and stdout.")
(The commit message says "stdout". It should have said "stderr".)
2025-04-25 17:43:47 +03:00
Lasse Collin
a6711d1c4a
Doxygen: Fix errors and some warnings in internal docs 2025-04-22 19:00:19 +03:00
Lasse Collin
516b90f6e1
liblzma: Update lzma_lzip_decoder() docs about trailing data
Don't say that the .lz format allows trailing data. According to the
lzip 1.25 manual, trailing data isn't part of the file format at all.
However, tools are still expected to behave as usefully as possible
when there is trailing data.

Fix the description of lzip >= 1.20 behavior when some of the first
bytes of trailing data match the magic bytes. While the lzip 1.25 manual
recommends that none of the first four bytes in trailing data should
match the magic bytes, the default behavior of lzip 1.25 treats
trailing data as a corrupt member header only if two or three bytes
match the magic bytes; one matching byte isn't enough.

Reported-by: Antonio Diaz Diaz
Link: https://www.mail-archive.com/xz-devel@tukaani.org/msg00702.html
2025-04-21 12:23:37 +03:00
Lasse Collin
dd006a67e5
liblzma: Update the lzma_lzip_decoder() docs about sync flush marker 2025-04-17 18:30:26 +03:00
Lasse Collin
f59c585960
xz: Don't mention lzip's sync flush marker on the man page
The sync flush marker isn't valid in .lz files. The sync flush marker
may be used by lzlib, but the resulting streams are only meant to be
decoded by lzlib itself. lzlib's docs make this clear.

Reported-by: Antonio Diaz Diaz
Link: https://www.mail-archive.com/xz-devel@tukaani.org/msg00700.html
Link: https://www.mail-archive.com/xz-devel@tukaani.org/msg00701.html
2025-04-17 18:16:40 +03:00
Lasse Collin
b5a5d9e3f7
liblzma: Disable CLMUL CRC on old MSVC targeting 32-bit x86
On GitHub runners, VS 2019 16.11 (MSVC 19.29.30158) results in
test failures. VS 2022 17.13 (MSVC 19.43.34808) works.

In xz 5.6.x there was a #pragma-based workaround for MSVC builds for
32-bit x86. Another method was thought to work with the new rewritten
CLMUL CRC. Apparently it doesn't. Keep it simple and disable CLMUL CRC
with any non-recent MSVC when building for 32-bit x86.

Fixes: 54eaea5ea49b ("liblzma: x86 CLMUL CRC: Rewrite")
Fixes: https://github.com/tukaani-project/xz/issues/171
Reported-by: Andrew Murray
2025-04-07 22:36:58 +03:00
Lasse Collin
c5fd88dfc3
liblzma: Remove MSVC hack from CLMUL CRC
It's not enough with MSVC 19.29 (VS 2019) even if the hack was also
applied to the CRC32 code. The tests crash when built for 32-bit x86.
2025-04-07 22:36:58 +03:00
Lasse Collin
a522a22654
Bump version and soname for 5.8.1 2025-04-03 14:34:43 +03:00
Lasse Collin
0c80045ab8
liblzma: mt dec: Fix lack of parallelization in single-shot decoding
Single-shot decoding means calling lzma_code() by giving it the whole
input at once and enough output buffer space to store the uncompressed
data, and combining this with LZMA_FINISH and no timeout
(lzma_mt.timeout = 0). This way the file is decoded with a single
lzma_code() call if possible.

The bug prevented the decoder from starting more than one worker thread
in single-shot mode. The issue was noticed when reviewing the code;
there are no bug reports. Thus maybe few have tried this mode.

Fixes: 64b6d496dc81 ("liblzma: Threaded decoder: Always wait for output if LZMA_FINISH is used.")
2025-04-03 14:34:42 +03:00
Lasse Collin
8188048854
liblzma: mt dec: Don't modify thr->in_size in the worker thread
Don't set thr->in_size = 0 when returning the thread to the stack of
available threads. Not only is it useless, but the main thread may
read the value in SEQ_BLOCK_THR_RUN. With valid inputs, it made
no difference if the main thread saw the original value or 0. With
invalid inputs (when worker thread stops early), thr->in_size was
no longer modified after the previous commit with the security fix
("Don't free the input buffer too early").

So while the bug appears harmless now, it's important to fix it because
the variable was being modified without proper locking. It's trivial
to fix because there is no need to change the value. Only main thread
needs to set the value in (in SEQ_BLOCK_THR_INIT) when starting a new
Block before the worker thread is activated.

Fixes: 4cce3e27f529 ("liblzma: Add threaded .xz decompressor.")
Reviewed-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Thanks-to: Sam James <sam@gentoo.org>
2025-04-03 14:34:42 +03:00
Lasse Collin
d5a2ffe41b
liblzma: mt dec: Don't free the input buffer too early (CVE-2025-31115)
The input buffer must be valid as long as the main thread is writing
to the worker-specific input buffer. Fix it by making the worker
thread not free the buffer on errors and not return the worker thread to
the pool. The input buffer will be freed when threads_end() is called.

With invalid input, the bug could at least result in a crash. The
effects include heap use after free and writing to an address based
on the null pointer plus an offset.

The bug has been there since the first committed version of the threaded
decoder and thus affects versions from 5.3.3alpha to 5.8.0.

As the commit message in 4cce3e27f529 says, I had made significant
changes on top of Sebastian's patch. This bug was indeed introduced
by my changes; it wasn't in Sebastian's version.

Thanks to Harri K. Koskinen for discovering and reporting this issue.

Fixes: 4cce3e27f529 ("liblzma: Add threaded .xz decompressor.")
Reported-by: Harri K. Koskinen <x64nop@nannu.org>
Reviewed-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Thanks-to: Sam James <sam@gentoo.org>
2025-04-03 14:34:42 +03:00
Lasse Collin
c0c835964d
liblzma: mt dec: Simplify by removing the THR_STOP state
The main thread can directly set THR_IDLE in threads_stop() which is
called when errors are detected. threads_stop() won't return the stopped
threads to the pool or free the memory pointed by thr->in anymore, but
it doesn't matter because the existing workers won't be reused after
an error. The resources will be cleaned up when threads_end() is
called (reinitializing the decoder always calls threads_end()).

Reviewed-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Thanks-to: Sam James <sam@gentoo.org>
2025-04-03 14:34:42 +03:00
Lasse Collin
831b55b971
liblzma: mt dec: Fix a comment
Reviewed-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Thanks-to: Sam James <sam@gentoo.org>
2025-04-03 14:34:42 +03:00
Lasse Collin
b9d168eee4
liblzma: Add assertions to lzma_bufcpy() 2025-04-03 14:34:30 +03:00
Lasse Collin
307c02ed69
sysdefs.h: Avoid <stdalign.h> even with C11 compilers
Oracle Developer Studio 12.6 on Solaris 10 claims C11 support in
__STDC_VERSION__ and supports _Alignas. However, <stdalign.h> is missing.
We only need alignas, so define it to _Alignas with C11/C17 compilers.
If something included <stdalign.h> later, it shouldn't cause problems.

Thanks to Ihsan Dogan for reporting the issue and testing the fix.

Fixes: c0e7eaae8d6eef1e313c9d0da20ccf126ec61f38
2025-03-29 12:41:32 +02:00
Lasse Collin
db9258e828
Bump version and soname for 5.8.0
Also remove the LZMA_UNSTABLE macro.
2025-03-25 15:18:32 +02:00
Lasse Collin
ff5d944749
liblzma: Count the extra bytes in LZMA/LZMA2 decoder memory usage 2025-03-25 15:18:31 +02:00