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

3114 Commits

Author SHA1 Message Date
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
Lasse Collin
1a4a4df366
Tests: test_index: Test lzma_index_memusage(STREAMS_MAX, 1) 2026-08-09 16:11:13 +03:00
Lasse Collin
d31b473917
liblzma: index.c: Define STREAMS_MAX 2026-08-09 16:11:03 +03:00
Lasse Collin
93372479ec
Tests: test_index: Extend _dup + _cat testing 2026-08-07 12:16:55 +03:00
Lasse Collin
a967036afb
liblzma: Index decoder: Detect a too large allocation earlier
Previously, if an Index had more than PREALLOC_MAX Records, then
allocations were done in PREALLOC_DEFAULT chunks (512 Records).
That makes little sense in practice because it's likely that one
would run out of address space later. Return LZMA_MEM_ERROR error
pre-emptively if PREALLOC_MAX would be exceeded.
2026-08-07 12:16:55 +03:00
Lasse Collin
9be8d5c91f
Update THANKS 2026-08-07 12:16:55 +03:00
Darren Carreras
d16c31196e
Tests: Add a test for the lzma_index_dup() + lzma_index_checks bug()
Link: https://github.com/tukaani-project/xz/pull/238
2026-08-07 12:16:55 +03:00
Darren Carreras
c57500bda5
liblzma: Preserve check statistics in lzma_index_dup()
lzma_index_dup() copied the per-Stream flags but not the cached bitmask
for all Streams except the last one. As a result, lzma_index_checks() on
a duplicated multi-Stream Index reported only the Check type of its
final Stream.

Fixes: https://github.com/tukaani-project/xz/pull/238
2026-08-07 12:16:45 +03:00
Lasse Collin
6097929ae8
Update THANKS 2026-07-21 13:56:42 +03:00
Lasse Collin
4b9b827117
xz: Free the filename read from the file specified with --files/--files0
Like the previous commit, this cleans up leak detection slightly.
Otherwise it doesn't matter because xz is going to exit soon anyway.
2026-07-21 13:50:13 +03:00
Lasse Collin
7bd6d63b0c
xz: Free the filename allocated for --files or --files0
This cleans up leak detection slightly. Otherwise it doesn't matter
because xz is going to exit soon anyway.

Reported-by: Phuc An
Fixes: https://github.com/tukaani-project/xz/pull/232
2026-07-21 13:32:05 +03:00
Lasse Collin
0877609467
liblzma: Fix input_size_max in lzma_index_buffer_decode()
If *in_pos > 0, the condition became more relaxed than it needed to be.

Fixes: 5005914f1acf ("liblzma: Index decoder: Reject an obviously-bad Number of>
Fixes: 0352dc7929b1 ("liblzma: Silence a compiler warning")
2026-07-21 12:58:45 +03:00
Lasse Collin
d4edae32b6
Tests: Fix test_index.c when encoding support is disabled
Fixes: 10dfae83fd3b ("Tests: test_index: Add a test for the Index decoder memusage bug")
2026-07-20 22:34:32 +03:00
Lasse Collin
0352dc7929
liblzma: Silence a compiler warning
Fixes: 5005914f1acf ("liblzma: Index decoder: Reject an obviously-bad Number of Records better")
2026-07-20 22:14:05 +03:00
Lasse Collin
47c44e9008
Tests: test_index: Test the stricter Number of Records condition 2026-07-20 21:16:17 +03:00
Lasse Collin
a9c92328bd
Tests: Add test file bad-0-index-1.xz 2026-07-20 21:16:17 +03:00