1
0
mirror of https://git.tukaani.org/xz.git synced 2026-10-31 03:14:56 +00:00

3129 Commits

Author SHA1 Message Date
Ali Ahmet Memiş
9e3a31f2fe
Tests: test_scripts.sh: Test xzdiff with one operand
The _z test is skipped if gzip isn't available.

Closes: https://github.com/tukaani-project/xz/pull/258
2026-10-28 13:44:44 +02:00
Ali Ahmet Memiş
1b1a508859
xzdiff: Fix the one-operand case with the _z suffix
The _z suffix was accepted when only one file was given, but the expr
that removes the suffix requires a - or . before it. FILE became empty:

$ xzdiff foo_z
diff: '': No such file or directory

Link: https://github.com/tukaani-project/xz/pull/258
2026-10-28 13:44:30 +02:00
Lasse Collin
5a0dbb19c6
xz: Silence a warning from Clang 23 when threading is disabled
src/xz/hardware.c:29:13: warning: variable 'use_mt_mode_with_one_thread' set but not used [-Wunused-but-set-global]
   29 | static bool use_mt_mode_with_one_thread = false;
      |             ^
2026-10-28 10:17:28 +02:00
LinkTheOperatorMatrix
299eb5c3f5
CMake: Fix wrong variable name in the MicroLZMA test condition
tests.cmake checked DECODERS instead of XZ_DECODERS. With
XZ_MICROLZMA_DECODER=OFF, test_microlzma was incorrectly added
to the list of tests, which resulted in a build failure.

Closes: https://github.com/tukaani-project/xz/pull/255
2026-10-16 16:21:02 +03:00
Lasse Collin
49b372b938
xz: Silence a Clang warning on Windows
From Clang 23.1.3:

src/xz/file_io.c:108:13: error: variable 'try_sparse' set but not used [-Werror,-Wunused-but-set-global]
  108 | static bool try_sparse = true;
      |             ^
2026-10-13 19:15:10 +03:00
Lasse Collin
b355a31140
Tests: Add test file bad-1-powerpc-1.xz 2026-10-10 16:59:30 +03:00
fhgffy
65e97f4826
lzmainfo: Open named files in binary mode
On native Windows, lzmainfo opened named .lzma files in text mode while
stdin was already binary. The C runtime treats 0x1A as EOF and translates
CRLF in the 13-byte header. A valid file with a known uncompressed size
of 26 bytes failed with "File is too small to be a .lzma file"; a known
size of 2573 bytes was incorrectly reported as 10 bytes. Reading the same
files through stdin or - reported the correct sizes.

Closes: https://github.com/tukaani-project/xz/pull/253
2026-10-09 18:21:33 +03:00
Lasse Collin
4ea5cd06c5
Translations: Add Chinese (traditional) man page translations 2026-10-06 22:24:55 +03:00
Lasse Collin
6d4309bd5f
Translations: Add Latvian translation 2026-10-03 14:58:03 +03:00
Lasse Collin
364ccb0f20
Translations: Update the Spanish translation 2026-10-03 14:25:27 +03:00
Lasse Collin
3b1efb04d1
Tests: Fix test_files.sh failure with --disable-xz
Reported-by: Otto Kekäläinen
Fixes: 7f539d14484e ("Tests: Test that integer overflow in xz --list totals is caught")
Fixes: https://github.com/tukaani-project/xz/issues/244
2026-09-09 22:37:17 +03:00
Lasse Collin
318fbc79be
doc/SHA256SUMS: Add 5.8.4 2026-09-09 17:57:34 +03:00
Lasse Collin
d3e650e63c
Bump version and soname for 5.8.4 v5.8.4 2026-09-09 17:32:12 +03:00
Lasse Collin
44a7fbdbe4
Add NEWS for 5.8.4 2026-09-09 17:32:04 +03:00
Lasse Collin
0d30919e73
Translations: Run po4a/update-po
This is to keep the files in release tarballs similar to the files
in the Git repository.
2026-09-09 15:19:46 +03:00
Lasse Collin
b33ffadd16
Translations: Run "make -C po update-po"
16 translations weren't updated after 102ea0ed1290 ("xz: Make it an error
if the totals in xz --list exceed UINT64_MAX").
2026-09-09 15:08:00 +03:00
Lasse Collin
df5bfb4547
Tests: Add a fuzzer for .xz Index decoding
Normal .xz decoding uses lzma_index_hash, so this new fuzzer doesn't
overlap with the existing fuzzers.
2026-09-09 14:35:57 +03:00
Lasse Collin
65198524f0
Tests: Make some memory allocations fail in fuzzers 2026-09-09 14:35:57 +03:00
Lasse Collin
d4217668a7
Tests: Reinitialize decoders twice in fuzzers 2026-09-09 14:35:57 +03:00
Lasse Collin
9c3661926e
Tests: fuzz_common.h: Reset next_out and avail_out
It matters if the same lzma_stream is reused.
2026-09-09 14:35:57 +03:00
Lasse Collin
16f3093144
Tests: Adjust coding style in fuzzers 2026-09-09 14:35:57 +03:00
Lasse Collin
c3b290c3dc
liblzma: Make lzma_simple_coder_init() reinit-safe after alloc failure
lzma_raw_coder_init() always calls lzma_next_end() if an error occurs
in filter initialization, and no other code path can call
lzma_simple_coder_init(), so this change doesn't fix any bug.
This is just to reduce likelyhood of future bugs.
2026-09-09 14:35:57 +03:00
Lasse Collin
ff834f25ae
Tests: Test lzma_alone_decoder() reuse after dictionary allocation failure
This test crashes if both of the two previous commits are reverted.
2026-09-09 14:35:46 +03:00
Lasse Collin
e5e63d50ea
liblzma: Clean up after a filter chain initialization error
Filter coders are initialized using lzma_next_filter_init(). If filter
chain initialization fails, the entire filter chain should be cleaned up
with lzma_next_end(). lzma_raw_encoder_init() and lzma_raw_decoder_init()
have always done this via lzma_raw_coder_init() in filter_common.c.
(Separate cleanup is weird, but it must have made sense to the young me.)

The following decoders initialize LZMA1 filter directly without using the
raw filter chain API. This avoids needlessly pulling in all other filters
when a program is linked against static liblzma. These functions didn't
call lzma_next_end() after an initialization error, which left the state
available for later reinitialization.

  - lzma_alone_decoder()
  - lzma_lzip_decoder()
  - lzma_auto_decoder() [*]
  - lzma_microlzma_decoder()

[*] lzma_auto_decoder() is only indirectly affected due to the first two
    functions. lzma_auto_decoder() itself doesn't need a fix.

There are also encoder functions that initialize the LZMA1 encoder
directly. They don't have this issue because the whole lzma_stream
is cleaned up when encoder initialization fails.

Reported-by: GitHub user christos-cantina-security (christos-spearbit)
2026-09-09 14:14:40 +03:00
Lasse Collin
fe4d763d56
liblzma: Make lzma_lz_decoder_init() safe to reinit after alloc failure
If memory allocation fails and the resulting coder state is reused,
ensure that memory allocation is attempted again. However, coders that
are initialized via lzma_next_filter_init() shouldn't be reinitialized
after failure; they should be cleaned up with lzma_next_end().

Reported-by: GitHub user christos-cantina-security (christos-spearbit)
2026-09-09 14:14:40 +03:00
Lasse Collin
9fc6f5cd87
liblzma: mt dec: Clarify comments about mutex usage 2026-09-04 12:56:15 +03:00
Trithem90
c6e3aadbb5
liblzma: mt dec: Protect progress_in update with mutex
Worker threads update coder->progress_in while holding coder->mutex, but
the main thread updated the same field without the mutex while decoding
the next Block Header. ThreadSanitizer reported the concurrent writes and
lzma_get_progress() under-reported input progress by one Block.

All other coder->progress_in/progress_out accesses in stream_decode_mt()
are done when the worker threads aren't active, so only the access in
SEQ_BLOCK_HEADER needs to lock coder->mutex.

Co-authored-by: Lasse Collin <lasse.collin@tukaani.org>
Fixes: 4cce3e27f529 ("liblzma: Add threaded .xz decompressor.")
Closes: https://github.com/tukaani-project/xz/pull/243
2026-09-04 12:56:15 +03:00
Lasse Collin
5121d1aed8
Tests: Add tests for single-call .xz encoding
Thanks-to: GitHub user androvonx95
Closes: https://github.com/tukaani-project/xz/pull/231
2026-09-04 12:56:07 +03:00
Lasse Collin
28a66a3d1b
Translations: Update the Italian translation 2026-08-20 16:40:01 +03:00
Lasse Collin
c6c425829c
liblzma: LZMA2 decoder: Be more strict about compressed chunk size
It wasn't really a bug, but it's good to be more strict.

Side effects ("downsides" would be a too strong word):

  - Now the LZMA decoder has to use the slow path at the end of every
    LZMA2 chunk even when the read position isn't close to &in[in_size].
    This doesn't matter in practice.

  - If a chunk header was corrupt exactly so that the compressed size is
    too small, now fewer bytes of uncompressed data can be recovered.

Reported-by: GitHub user christos-spearbit
2026-08-20 16:38:42 +03:00
Lasse Collin
c077edfd18
Translations: Update the Polish translation 2026-08-19 22:58:43 +03:00
Lasse Collin
936e72e20e
Translations: Update the German translation 2026-08-19 20:26:37 +03:00
Lasse Collin
11334a5d4d
Translations: Update the Korean translation 2026-08-19 19:07:34 +03:00
Lasse Collin
7b9955d0aa
Translations: Update the Portuguese translation 2026-08-19 19:05:42 +03:00
Lasse Collin
9ed91f3afe
Translations: Update the Dutch translation 2026-08-19 14:03:55 +03:00
Lasse Collin
e38f738e5c
Translations: Update the Romanian translation 2026-08-18 20:20:57 +03:00
Lasse Collin
f9a0f80e35
Translations: Update the Croatian translation 2026-08-18 18:20:17 +03:00
Lasse Collin
b1b54af595
Translations: Update the Ukrainian translation 2026-08-18 13:05:22 +03:00
Lasse Collin
0072f6c9bc
Translations: Restore SPDX license identifier to pt_BR.po
Fixes: 8d13dd61ecb7 ("Translations: Update the Brazilian Portuguese translation")
2026-08-17 20:31:41 +03:00
Lasse Collin
7f539d1448
Tests: Test that integer overflow in xz --list totals is caught 2026-08-15 19:56:09 +03:00
Lasse Collin
490ca91153
Tests: Add test file bad-1-index-huge-uncomp.xz 2026-08-15 19:56:09 +03:00
xordanblu
102ea0ed12
xz: Make it an error if the totals in xz --list exceed UINT64_MAX
If at least three files are passed to xz --list, the totals might exceed
the range of uint64_t. Previously wrong totals were displayed in this
case. Now an error is shown as soon as an overflow would occur, and the
remaining files aren't processed. In most other cases an error doesn't
prevent xz from processing the remaining files, but in this case it
feels OK because (1) the error should be very rare, (2) it keeps the
code slightly simpler, and (3) with xz --robot --list the caller will
likely ignore the output anyway when xz exits with a non-zero status.

Co-authored-by: Lasse Collin <lasse.collin@tukaani.org>
Fixes: https://github.com/tukaani-project/xz/pull/240
2026-08-15 19:56:09 +03:00
Lasse Collin
29f9ca3dbc
liblzma: index.c 4/4: Reverse the tree building for index_streams
lzma_index_cat() is used by lzma_file_info_decoder() and by a few apps
that were written before lzma_file_info_decoder() existed (it was added
in 5.3.1alpha). The most common use case for these functions is xz --list.
The other use case is random access decoding.

When decoding Index fields from multi-Stream .xz files, lzma_index_cat()
is used to concatenate the decoded lzma_index structures. Such decoding
starts from the last Stream in the file and stops at the first Stream in
the file, so lzma_index_cat() is called with the most recently decoded
Stream as the destination argument while the source argument contains all
other Streams that have been decoded so far. That is, the typical use case
is lzma_index_cat(one_stream, many_streams, NULL).

With the old code, lzma_index_cat() appended Streams from src into dest
one at a time and updated their absolute offsets at the same time.
When a .xz file contained many Streams, the number of Streams in
the source argument grew for each call, which created a performance
problem if the file contained an unusually large number of Streams
(over 10,000). (A large number of Blocks isn't a problem.)

Make lzma_index_cat() prepend the index_streams from dest to src
instead of appending from src to dest. Use the _bias members to adjust
the offsets of the existing index_streams in src.

Change the numbering in index_stream.number from 1, 2, 3, ... to
...., 2, 1, 0. That is, internally the last index_stream is now 0.

Now lzma_index_cat() needs to update all Streams from dest instead from
src, which keeps the normal use case fast. Obviously the performance
problem still exists, but now it's in the opposite situation (repeated
calls of lzma_index_cat(many_streams, one_stream, NULL)). This should
be acceptable because there should be no use cases where doing it would
be useful. A full fix would require a more complex patch.

As an alternative, I tried a rewrite of index.c that replaces the trees
with plain arrays and realloc(). It's smaller and simpler, but it's
still somewhat complex because the API is too flexible compared to what
functionality is actually needed. I didn't merge that version because
a rewrite has a higher risk of regressions, and in some corner cases
the peak memory usage was considerably higher than with the old code
(if a custom lzma_allocator is used, realloc() has to be emulated with
alloc + memcpy + free, and native realloc() might need to do that too),
and large preallocations make it unclear what lzma_index_memusage() and
lzma_index_memused() should return.

Below is an example where xz --list became too slow before this commit.
Pass 18 or 20 instead of 16 to seq, and xz effectively hangs.

    true | xz > big.xz
    for I in $(seq 16)
    do
        cat big.xz big.xz > tmp.xz
        mv tmp.xz big.xz
        echo ====
        echo $I
        time xz -l big.xz
    done

Reported-by: Omkhar Arasaratnam
2026-08-15 19:56:09 +03:00
Lasse Collin
869f0e85a8
liblzma: index.c 3/4: Add index_tree_prev() 2026-08-15 19:56:09 +03:00
Lasse Collin
0543606d15
liblzma: index.c 2/4: Make index_tree_append support prepending too 2026-08-15 19:56:09 +03:00
Lasse Collin
59cac26b80
liblzma: index.c 1/4: Add bias members
In this commit the biases are still constant.
2026-08-15 19:56:02 +03:00
Lasse Collin
f8f53ca1fb
CI: MSVC: Build shared liblzma 2026-08-15 19:41:39 +03:00
Lasse Collin
8697fcc823
Update .gitignore 2026-08-15 19:41:39 +03:00
Lasse Collin
18769dd692
CMake: Don't put test binaries in a subdirectory
This can matter on Windows:

 - MSVC puts the binaries into subdirectories based on build type
   (like "Debug" or "Release"), and then the test executables won't
   find liblzma.dll because it's not in the working directory from
   which the tests are run.

 - With mingw-w64, liblzma.dll was in the working directory so the test
   executables worked. However, the if the system happened to have
   liblzma.dll in, for example, the Windows directory, then the DLL
   search order might pick that instead.

Putting the shared library and test executables in the same directory
avoids these problems.

Reported-by: Frank <mail@franku.nl>
Fixes: https://github.com/tukaani-project/xz/pull/239
2026-08-15 19:41:29 +03:00
Lasse Collin
c8b8ab2ef1
liblzma: Fix a theoretical integer overflow in lzma_index_cat()
To trigger it, one would need to successfully allocate hundreds of
gigabytes of memory.
2026-08-09 16:11:13 +03:00