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

3102 Commits

Author SHA1 Message Date
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
Lasse Collin
006126aca9
Revert "liblzma: Add internal constant INDEX_RECORDS_MAX"
This reverts commit 9ff4dadca96a5ac3cb478759a4fdb8663be114eb.
The INDEX_RECORDS_MAX constant isn't needed after the previous commit.
2026-07-20 21:16:17 +03:00
Lasse Collin
5005914f1a
liblzma: Index decoder: Reject an obviously-bad Number of Records better
File info decoder knows Backward Size, so pass it to the Index decoder.
Now the Index decoder, when called from the file info decoder, won't
allocate a large amount of memory when Backward Size is tiny and the
Number of Records field contains a huge invalid value.

If a reasonable memory usage limit was set, the old code returned
LZMA_MEMLIMIT_ERROR if the value in Number of Records was too huge.
Now it results in LZMA_DATA_ERROR which is better.
2026-07-20 21:16:17 +03:00
Lasse Collin
10dfae83fd
Tests: test_index: Add a test for the Index decoder memusage bug 2026-07-20 21:16:17 +03:00
Lasse Collin
bd3bfe8346
liblzma: Index decoder: Fix lzma_memusage()
If lzma_stream was initialized using lzma_index_decoder() or
lzma_file_info_decoder(), and lzma_memusage() was called after a few
Records had already been decoded, the return value was too low because
it was calculated based on the number of Records that haven't been
decoded yet. So near the end of a big Index, the return value would be
tiny compared to the actual memory usage.

It worked correctly in the primary use case, that is, after
LZMA_MEMLIMIT_ERROR. Thus, in practice this bug didn't matter much.
2026-07-20 21:16:17 +03:00
Lasse Collin
2187b27c64
Tests: test_index: Fix testing of _locate() with concatenated lzma_index 2026-07-20 21:16:11 +03:00
Lasse Collin
8d13dd61ec
Translations: Update the Brazilian Portuguese translation 2026-07-19 10:45:31 +03:00
Lasse Collin
791ce1bb6d
liblzma: Remove an outdated API doc in hardware.h 2026-07-19 10:40:44 +03:00
Lasse Collin
f3b5688159
Tests: Comment that a sanitizer may be needed for lzma_index_append() bug
Fixes: a3ea8832bec1 ("Tests: Add a test for the lzma_index_prealloc() + lzma_index_append() bug")
Link: https://github.com/tukaani-project/xz/issues/233
2026-07-03 16:55:03 +03:00
Lasse Collin
6a07932a87
Translations: Update the Croatian translation 2026-07-02 21:56:33 +03:00
Lasse Collin
b8d0707ae7
NEWS: Clarify which bug is CVE-2026-34743
Fixes: https://salsa.debian.org/debian/xz-utils/-/merge_requests/5#note_775071
2026-07-02 21:09:36 +03:00
Lasse Collin
e95cd90da9
Translations: Fix LTR/RTL issue in Arabic xz man page tables
The headings are RTL but in some tables the rows were LTR because the
first strong char was LTR, like the "e" in "-0e". Add {RLM}{LRM}...{RLM}
to those columns ("-0" to "-9", and "-0e" to "-9e"):

    sed -ri $'/^msgstr /{s/"(-[0-9]e?)"/"\u200f\u200e\\1\u200f"/}' ar.po

It's not perfect because groff doesn't treat RLM and LRM as zero-width
chars, and thus the columns are slightly misaligned. It's good enough
in practice still.

Thanks-to: Zayed Al-Saidi <zayed.alsaidi@gmail.com>
2026-06-21 20:53:49 +03:00
Lasse Collin
b46944d734
CI: Add 'timeout: 10' to coverity.yml 2026-06-21 20:53:49 +03:00