]> git.ipfire.org Git - thirdparty/xz.git/log
thirdparty/xz.git
2 years agoliblzma: Stream decoder: Fix restarting after LZMA_MEMLIMIT_ERROR.
Lasse Collin [Wed, 28 Sep 2022 08:05:15 +0000 (11:05 +0300)] 
liblzma: Stream decoder: Fix restarting after LZMA_MEMLIMIT_ERROR.

If lzma_code() returns LZMA_MEMLIMIT_ERROR it is now possible
to use lzma_memlimit_set() to increase the limit and continue
decoding. This was supposed to work from the beginning but
there was a bug. With other decoders (.lzma or threaded .xz)
this already worked correctly.

2 years agoliblzma: Stream decoder: Fix comments.
Lasse Collin [Wed, 28 Sep 2022 08:00:23 +0000 (11:00 +0300)] 
liblzma: Stream decoder: Fix comments.

2 years agoliblzma: ARM64: Add comments.
Lasse Collin [Tue, 20 Sep 2022 13:58:22 +0000 (16:58 +0300)] 
liblzma: ARM64: Add comments.

2 years agoliblzma: ARM64: Fix wrong comment in API doc.
Lasse Collin [Tue, 20 Sep 2022 13:27:50 +0000 (16:27 +0300)] 
liblzma: ARM64: Fix wrong comment in API doc.

Thanks to Jia Tan.

2 years agoxz: Add --experimental-arm64[=width=WIDTH].
Lasse Collin [Mon, 19 Sep 2022 17:24:26 +0000 (20:24 +0300)] 
xz: Add --experimental-arm64[=width=WIDTH].

It will be renamed to --arm64 once it is stable.

Man page or --long-help weren't updated yet.

2 years agoliblzma: Add experimental ARM64 BCJ filter with a temporary Filter ID.
Lasse Collin [Mon, 19 Sep 2022 16:34:56 +0000 (19:34 +0300)] 
liblzma: Add experimental ARM64 BCJ filter with a temporary Filter ID.

That is, the Filter ID will be changed once the design is final.
The current version will be removed. So files created with the
tempoary Filter ID won't be supported in the future.

2 years agoliblzma: Simple/BCJ filters: Allow disabling generic BCJ options.
Lasse Collin [Sat, 17 Sep 2022 19:42:18 +0000 (22:42 +0300)] 
liblzma: Simple/BCJ filters: Allow disabling generic BCJ options.

This will be needed for the ARM64 BCJ filter as it will use
its own options struct.

2 years agoTests: Add a test file for lzma_index_append() integer overflow bug.
Lasse Collin [Fri, 16 Sep 2022 14:08:53 +0000 (17:08 +0300)] 
Tests: Add a test file for lzma_index_append() integer overflow bug.

This test fails before commit 18d7facd3802b55c287581405c4d49c98708c136.

test_files.sh now runs xz -l for bad-3-index-uncomp-overflow.xz
because only then the previously-buggy code path gets tested.
Normal decompression doesn't use lzma_index_append() at all.
Instead, lzma_index_hash functions are used and those already
did the overflow check.

2 years agoTranslations: Add Turkish translation.
Lasse Collin [Fri, 16 Sep 2022 12:10:07 +0000 (15:10 +0300)] 
Translations: Add Turkish translation.

2 years agoUpdate THANKS.
Lasse Collin [Fri, 16 Sep 2022 11:09:07 +0000 (14:09 +0300)] 
Update THANKS.

2 years agoxzgrep: Fix compatibility with old shells.
Lasse Collin [Fri, 16 Sep 2022 11:07:03 +0000 (14:07 +0300)] 
xzgrep: Fix compatibility with old shells.

Running the current xzgrep on Slackware 10.1 with GNU bash 3.00.15:

    xzgrep: line 231: syntax error near unexpected token `;;'

On SCO OpenServer 5.0.7 with Korn Shell 93r:

    syntax error at line 231 : `;;' unexpected

Turns out that some old shells don't like apostrophes (') inside
command substitutions. For example, the following fails:

    x=$(echo foo
    # asdf'zxcv
    echo bar)
    printf '%s\n' "$x"

The problem was introduced by commits
69d1b3fc29677af8ade8dc15dba83f0589cb63d6 (2022-03-29),
bd7b290f3fe4faeceb7d3497ed9bf2e6ed5e7dc5 (2022-07-18), and
a648978b20495b7aa4a8b029c5a810b5ad9d08ff (2022-07-19).
5.2.6 is the only stable release that included
this problem.

Thanks to Kevin R. Bulgrien for reporting the problem
on SCO OpenServer 5.0.7 and for providing the fix.

2 years agoTests: Silence warnings about unused functions from tuktest.h.
Lasse Collin [Fri, 9 Sep 2022 11:12:30 +0000 (14:12 +0300)] 
Tests: Silence warnings about unused functions from tuktest.h.

Warnings about unused tuktest_run_test conveniently tell which
test programs haven't been converted to tuktest.h yet but I
silenced that warning too for now anyway.

It is fine to use __attribute__((__unused__)) even when the
function is actually used because the attribute only means
that the function might be unused.

2 years agoliblzma: lzma_filters_copy: Keep dest[] unmodified if an error occurs.
Lasse Collin [Fri, 9 Sep 2022 10:51:57 +0000 (13:51 +0300)] 
liblzma: lzma_filters_copy: Keep dest[] unmodified if an error occurs.

lzma_stream_encoder() and lzma_stream_encoder_mt() always assumed
this. Before this patch, failing lzma_filters_copy() could result
in free(invalid_pointer) or invalid memory reads in stream_encoder.c
or stream_encoder_mt.c.

To trigger this, allocating memory for a filter options structure
has to fail. These are tiny allocations so in practice they very
rarely fail.

Certain badness in the filter chain array could also make
lzma_filters_copy() fail but both stream_encoder.c and
stream_encoder_mt.c validate the filter chain before
trying to copy it, so the crash cannot occur this way.

2 years agoliblzma: lzma_index_append: Add missing integer overflow check.
Jia Tan [Fri, 2 Sep 2022 12:18:55 +0000 (20:18 +0800)] 
liblzma: lzma_index_append: Add missing integer overflow check.

The documentation in src/liblzma/api/lzma/index.h suggests that
both the unpadded (compressed) size and the uncompressed size
are checked for overflow, but only the unpadded size was checked.
The uncompressed check is done first since that is more likely to
occur than the unpadded or index field size overflows.

2 years agoUpdate THANKS.
Lasse Collin [Thu, 8 Sep 2022 12:11:08 +0000 (15:11 +0300)] 
Update THANKS.

2 years agoCMake: Clarify a comment about Windows symlinks without file extension.
Jia Tan [Thu, 8 Sep 2022 12:07:00 +0000 (15:07 +0300)] 
CMake: Clarify a comment about Windows symlinks without file extension.

2 years agoCMake: Update for liblzma_*.map files and fix wrong common_w32res.rc dep.
Lasse Collin [Thu, 8 Sep 2022 12:02:41 +0000 (15:02 +0300)] 
CMake: Update for liblzma_*.map files and fix wrong common_w32res.rc dep.

The previous commit split liblzma.map into liblzma_linux.map and
liblzma_generic.map. This commit updates the CMake build for those.

common_w32res.rc dependency was listed under Linux/FreeBSD while
obviously it belongs to Windows when building a DLL.

2 years agoliblzma: Vaccinate against an ill patch from RHEL/CentOS 7.
Lasse Collin [Sun, 4 Sep 2022 20:23:00 +0000 (23:23 +0300)] 
liblzma: Vaccinate against an ill patch from RHEL/CentOS 7.

RHEL/CentOS 7 shipped with 5.1.2alpha, including the threaded
encoder that is behind #ifdef LZMA_UNSTABLE in the API headers.
In 5.1.2alpha these symbols are under XZ_5.1.2alpha in liblzma.map.
API/ABI compatibility tracking isn't done between development
releases so newer releases didn't have XZ_5.1.2alpha anymore.

Later RHEL/CentOS 7 updated xz to 5.2.2 but they wanted to keep
the exported symbols compatible with 5.1.2alpha. After checking
the ABI changes it turned out that >= 5.2.0 ABI is backward
compatible with the threaded encoder functions from 5.1.2alpha
(but not vice versa as fixes and extensions to these functions
were made between 5.1.2alpha and 5.2.0).

In RHEL/CentOS 7, XZ Utils 5.2.2 was patched with
xz-5.2.2-compat-libs.patch to modify liblzma.map:

  - XZ_5.1.2alpha was added with lzma_stream_encoder_mt and
    lzma_stream_encoder_mt_memusage. This matched XZ Utils 5.1.2alpha.

  - XZ_5.2 was replaced with XZ_5.2.2. It is clear that this was
    an error; the intention was to keep using XZ_5.2 (XZ_5.2.2
    has never been used in XZ Utils). So XZ_5.2.2 lists all
    symbols that were listed under XZ_5.2 before the patch.
    lzma_stream_encoder_mt and _mt_memusage are included too so
    they are listed both here and under XZ_5.1.2alpha.

The patch didn't add any __asm__(".symver ...") lines to the .c
files. Thus the resulting liblzma.so exports the threaded encoder
functions under XZ_5.1.2alpha only. Listing the two functions
also under XZ_5.2.2 in liblzma.map has no effect without
matching .symver lines.

The lack of XZ_5.2 in RHEL/CentOS 7 means that binaries linked
against unpatched XZ Utils 5.2.x won't run on RHEL/CentOS 7.
This is unfortunate but this alone isn't too bad as the problem
is contained within RHEL/CentOS 7 and doesn't affect users
of other distributions. It could also be fixed internally in
RHEL/CentOS 7.

The second problem is more serious: In XZ Utils 5.2.2 the API
headers don't have #ifdef LZMA_UNSTABLE for obvious reasons.
This is true in RHEL/CentOS 7 version too. Thus now programs
using new APIs can be compiled without an extra #define. However,
the programs end up depending on symbol version XZ_5.1.2alpha
(and possibly also XZ_5.2.2) instead of XZ_5.2 as they would
with an unpatched XZ Utils 5.2.2. This means that such binaries
won't run on other distributions shipping XZ Utils >= 5.2.0 as
they don't provide XZ_5.1.2alpha or XZ_5.2.2; they only provide
XZ_5.2 (and XZ_5.0). (This includes RHEL/CentOS 8 as the patch
luckily isn't included there anymore with XZ Utils 5.2.4.)

Binaries built by RHEL/CentOS 7 users get distributed and then
people wonder why they don't run on some other distribution.
Seems that people have found out about the patch and been copying
it to some build scripts, seemingly curing the symptoms but
actually spreading the illness further and outside RHEL/CentOS 7.

The ill patch seems to be from late 2016 (RHEL 7.3) and in 2017 it
had spread at least to EasyBuild. I heard about the events only
recently. :-(

This commit splits liblzma.map into two versions: one for
GNU/Linux and another for other OSes that can use symbol versioning
(FreeBSD, Solaris, maybe others). The Linux-specific file and the
matching additions to .c files add full compatibility with binaries
that have been built against a RHEL/CentOS-patched liblzma. Builds
for OSes other than GNU/Linux won't get the vaccine as they should
be immune to the problem (I really hope that no build script uses
the RHEL/CentOS 7 patch outside GNU/Linux).

The RHEL/CentOS compatibility symbols XZ_5.1.2alpha and XZ_5.2.2
are intentionally put *after* XZ_5.2 in liblzma_linux.map. This way
if one forgets to #define HAVE_SYMBOL_VERSIONS_LINUX when building,
the resulting liblzma.so.5 will have lzma_stream_encoder_mt@@XZ_5.2
since XZ_5.2 {...} is the first one that lists that function.
Without HAVE_SYMBOL_VERSIONS_LINUX @XZ_5.1.2alpha and @XZ_5.2.2
will be missing but that's still a minor problem compared to
only having lzma_stream_encoder_mt@@XZ_5.1.2alpha!

The "local: *;" line was moved to XZ_5.0 so that it doesn't need
to be moved around. It doesn't matter where it is put.

Having two similar liblzma_*.map files is a bit silly as it is,
at least for now, easily possible to generate the generic one
from the Linux-specific file. But that adds extra steps and
increases the risk of mistakes when supporting more than one
build system. So I rather maintain two files in parallel and let
validate_map.sh check that they are in sync when "make mydist"
is run.

This adds .symver lines for lzma_stream_encoder_mt@XZ_5.2.2 and
lzma_stream_encoder_mt_memusage@XZ_5.2.2 even though these
weren't exported by RHEL/CentOS 7 (only @@XZ_5.1.2alpha was
for these two). I added these anyway because someone might
misunderstand the RHEL/CentOS 7 patch and think that @XZ_5.2.2
(@@XZ_5.2.2) versions were exported too.

At glance one could suggest using __typeof__ to copy the function
prototypes when making aliases. However, this doesn't work trivially
because __typeof__ won't copy attributes (lzma_nothrow, lzma_pure)
and it won't change symbol visibility from hidden to default (done
by LZMA_API()). Attributes could be copied with __copy__ attribute
but that needs GCC 9 and a fallback method would be needed anyway.

This uses __symver__ attribute with GCC >= 10 and
__asm__(".symver ...") with everything else. The attribute method
is required for LTO (-flto) support with GCC. Using -flto with
GCC older than 10 is now broken on GNU/Linux and will not be fixed
(can silently result in a broken liblzma build that has dangerously
incorrect symbol versions). LTO builds with Clang seem to work
with the traditional __asm__(".symver ...") method.

Thanks to Boud Roukema for reporting the problem and discussing
the details and testing the fix.

2 years agoCMake: Add xz symlinks.
Lasse Collin [Wed, 31 Aug 2022 13:42:04 +0000 (16:42 +0300)] 
CMake: Add xz symlinks.

These are a minor thing especially since the xz build has
some real problems still like lack of large file support
on 32-bit systems but I'll commit this since the code exists.

Thanks to Jia Tan.

2 years agoCMake: Put xz man page install under if(UNIX) like is for xzdec.
Lasse Collin [Wed, 31 Aug 2022 13:29:38 +0000 (16:29 +0300)] 
CMake: Put xz man page install under if(UNIX) like is for xzdec.

Thanks to Jia Tan.

2 years agoBump version number for 5.3.3alpha. v5.3.3alpha
Lasse Collin [Mon, 22 Aug 2022 15:16:40 +0000 (18:16 +0300)] 
Bump version number for 5.3.3alpha.

2 years agoAdd NEWS for 5.3.3alpha.
Lasse Collin [Mon, 22 Aug 2022 15:13:56 +0000 (18:13 +0300)] 
Add NEWS for 5.3.3alpha.

2 years agoTranslations: Add Portuguese translation.
Lasse Collin [Tue, 12 Jul 2022 14:59:41 +0000 (17:59 +0300)] 
Translations: Add Portuguese translation.

Jia Tan made white-space changes and also changed "Language: pt_BR\n"
to pt. The translator wasn't reached so I'm hoping these changes
are OK and will commit it without translator's approval.

Thanks to Pedro Albuquerque and Jia Tan.

2 years agoTranslations: Add Serbian translation.
Lasse Collin [Sun, 10 Jul 2022 18:16:40 +0000 (21:16 +0300)] 
Translations: Add Serbian translation.

Quite a few white-space changes were made by Jia Tan to make
this look good. Contacting the translator didn't succeed so
I'm committing this without getting translator's approval.

Thanks to Мирослав Николић (Miroslav Nikolic) and Jia Tan.

2 years agoTranslations: Add Swedish translation.
Lasse Collin [Mon, 4 Jul 2022 20:51:36 +0000 (23:51 +0300)] 
Translations: Add Swedish translation.

Thanks to Sebastian Rasmussen and Jia Tan.

2 years agoTranslations: Add Esperanto translation.
Lasse Collin [Mon, 4 Jul 2022 20:40:27 +0000 (23:40 +0300)] 
Translations: Add Esperanto translation.

Thanks to Keith Bowes and Jia Tan.

2 years agoTranslations: Add Catalan translation.
Lasse Collin [Thu, 30 Jun 2022 21:22:33 +0000 (00:22 +0300)] 
Translations: Add Catalan translation.

Thanks to Jordi Mas and Jia Tan.

2 years agoTranslations: Add Ukrainian translation.
Lasse Collin [Thu, 30 Jun 2022 14:47:08 +0000 (17:47 +0300)] 
Translations: Add Ukrainian translation.

Thanks to Yuri Chornoivan and Jia Tan.

2 years agoTranslators: Add Romanian translation.
Lasse Collin [Thu, 30 Jun 2022 14:45:26 +0000 (17:45 +0300)] 
Translators: Add Romanian translation.

Thanks to Remus-Gabriel Chelu and Jia Tan.

2 years agoTranslations: Update Brazilian Portuguese translation.
Lasse Collin [Wed, 29 Jun 2022 15:33:32 +0000 (18:33 +0300)] 
Translations: Update Brazilian Portuguese translation.

One msgstr was changed. The diff is long due to changes
in the source code line numbers in the comments.

Thanks to Rafael Fontenelle.

2 years agoTranslations: Add Croatian translation.
Lasse Collin [Wed, 29 Jun 2022 15:04:44 +0000 (18:04 +0300)] 
Translations: Add Croatian translation.

Thanks to Božidar Putanec and Jia Tan.

2 years agoTranslations: Add Spanish translation.
Lasse Collin [Wed, 29 Jun 2022 14:58:48 +0000 (17:58 +0300)] 
Translations: Add Spanish translation.

Thanks to Cristian Othón Martínez Vera and Jia Tan.

2 years agoTranslations: Add Korean translation.
Lasse Collin [Wed, 29 Jun 2022 14:49:43 +0000 (17:49 +0300)] 
Translations: Add Korean translation.

Thanks to Seong-ho Cho and Jia Tan.

2 years agoTranslations: Rebuild cs.po to avoid incorrect fuzzy strings.
Lasse Collin [Mon, 16 Mar 2020 19:57:21 +0000 (21:57 +0200)] 
Translations: Rebuild cs.po to avoid incorrect fuzzy strings.

"make dist" updates the .po files and the fuzzy strings would
result in multiple very wrong translations.

2 years agoTranslations: Add partial Danish translation.
Lasse Collin [Mon, 16 Mar 2020 15:30:39 +0000 (17:30 +0200)] 
Translations: Add partial Danish translation.

I made a few minor white space changes without getting them
approved by the Danish translation team.

2 years agoTranslations: Add hu, zh_CN, and zh_TW.
Lasse Collin [Wed, 11 Mar 2020 20:37:54 +0000 (22:37 +0200)] 
Translations: Add hu, zh_CN, and zh_TW.

I made a few white space changes to these without getting them
approved by the translation teams. (I tried to contact the hu and
zh_TW teams but didn't succeed. I didn't contact the zh_CN team.)

2 years agoTranslations: Update vi.po to match the file from the TP.
Lasse Collin [Wed, 11 Mar 2020 12:33:30 +0000 (14:33 +0200)] 
Translations: Update vi.po to match the file from the TP.

The translated strings haven't been updated but word wrapping
is different.

2 years agoTranslations: Add fi and pt_BR, and update de, fr, it, and pl.
Lasse Collin [Wed, 11 Mar 2020 12:18:03 +0000 (14:18 +0200)] 
Translations: Add fi and pt_BR, and update de, fr, it, and pl.

The German translation isn't identical to the file in
the Translation Project but the changes (white space changes
only) were approved by the translator Mario Blättermann.

2 years agoxz: Try to clarify --memlimit-mt-decompress vs. --memlimit-compress.
Lasse Collin [Mon, 22 Aug 2022 14:27:19 +0000 (17:27 +0300)] 
xz: Try to clarify --memlimit-mt-decompress vs. --memlimit-compress.

2 years agoCMake: Add liblzma tests.
Lasse Collin [Mon, 22 Aug 2022 13:46:18 +0000 (16:46 +0300)] 
CMake: Add liblzma tests.

Thanks to Jia Tan for the patch.

2 years agoxz: Revise --info-memory output.
Lasse Collin [Fri, 19 Aug 2022 20:32:22 +0000 (23:32 +0300)] 
xz: Revise --info-memory output.

The strings could be more descriptive but it's good
to have some version of this committed now.

--robot mode wasn't changed yet.

2 years agoxz: Update the man page for threaded decompression and memlimits.
Lasse Collin [Fri, 19 Aug 2022 20:12:02 +0000 (23:12 +0300)] 
xz: Update the man page for threaded decompression and memlimits.

This documents the changes made in commits
6c6da57ae2aa962aabde6892442227063d87e88c,
cad299008cf73ec566f0662a9cf2b94f86a99659, and
898faa97287a756231c663a3ed5165672b417207.

The --info-memory bit hasn't been finished yet
even though it's already mentioned in this commit
under --memlimit-mt-decompress and --threads.

2 years agoBuild: Include the CMake files in the distribution.
Lasse Collin [Thu, 18 Aug 2022 14:49:16 +0000 (17:49 +0300)] 
Build: Include the CMake files in the distribution.

This was supposed to be done in 2020 with 5.2.5 release
already but it was noticed only today. 5.2.5 and 5.2.6
even mention experiemental CMake support in the NEWS entries.

Thanks to Olivier B. for reporting the problem.

2 years agoWindows: Fix broken liblzma.dll build with Visual Studio project files.
Lasse Collin [Thu, 18 Aug 2022 14:38:05 +0000 (17:38 +0300)] 
Windows: Fix broken liblzma.dll build with Visual Studio project files.

The bug was introduced in 352ba2d69af2136bc814aa1df1a132559d445616
"Windows: Fix building of resource files when config.h isn't used."

That commit fixed liblzma.dll build with CMake while keeping it
working with Autotools on Windows but the VS project files were
forgotten.

I haven't tested these changes.

Thanks to Olivier B. for reporting the bug and for the initial patch.

2 years agoliblzma: Threaded decoder: Improve LZMA_FAIL_FAST when LZMA_FINISH is used.
Lasse Collin [Thu, 18 Aug 2022 14:16:49 +0000 (17:16 +0300)] 
liblzma: Threaded decoder: Improve LZMA_FAIL_FAST when LZMA_FINISH is used.

It will now return LZMA_DATA_ERROR (not LZMA_OK or LZMA_BUF_ERROR)
if LZMA_FINISH is used and there isn't enough input to finish
decoding the Block Header or the Block. The use of LZMA_DATA_ERROR
is simpler and the less risky than LZMA_BUF_ERROR but this might
be changed before 5.4.0.

2 years agoAdd NEWS for 5.2.6.
Lasse Collin [Fri, 12 Aug 2022 15:31:47 +0000 (18:31 +0300)] 
Add NEWS for 5.2.6.

2 years agoAdd Jia Tan to AUTHORS.
Lasse Collin [Fri, 12 Aug 2022 11:28:41 +0000 (14:28 +0300)] 
Add Jia Tan to AUTHORS.

3 years agoBuild: Start the generated ChangeLog from around 5.2.0 instead of 5.0.0.
Lasse Collin [Mon, 25 Jul 2022 16:28:26 +0000 (19:28 +0300)] 
Build: Start the generated ChangeLog from around 5.2.0 instead of 5.0.0.

This makes ChangeLog smaller.

3 years agoTranslations: Change the copyright comment string to use with po4a.
Lasse Collin [Mon, 25 Jul 2022 16:11:05 +0000 (19:11 +0300)] 
Translations: Change the copyright comment string to use with po4a.

This affects the second line in po4a/xz-man.pot. The man pages of
xzdiff, xzgrep, and xzmore are from GNU gzip and under GNU GPLv2+
while the rest of the man pages are in the public domain.

3 years agoliblzma: Refactor lzma_mf_is_supported() to use a switch-statement.
Jia Tan [Mon, 25 Jul 2022 15:30:05 +0000 (18:30 +0300)] 
liblzma: Refactor lzma_mf_is_supported() to use a switch-statement.

3 years agoBuild: Don't allow empty LIST in --enable-match-finders=LIST.
Jia Tan [Mon, 25 Jul 2022 15:20:01 +0000 (18:20 +0300)] 
Build: Don't allow empty LIST in --enable-match-finders=LIST.

It's enforced only when a match finder is needed, that is,
when LZMA1 or LZMA2 encoder is enabled.

3 years agoxz: Update the man page that change to --keep will be in 5.2.6.
Lasse Collin [Sun, 24 Jul 2022 10:27:48 +0000 (13:27 +0300)] 
xz: Update the man page that change to --keep will be in 5.2.6.

3 years agoUpdate THANKS.
Lasse Collin [Tue, 19 Jul 2022 20:23:54 +0000 (23:23 +0300)] 
Update THANKS.

3 years agoCMake: Add missing source file to liblzma build
Nicholas Jackson [Mon, 18 Jul 2022 00:39:23 +0000 (17:39 -0700)] 
CMake: Add missing source file to liblzma build

3 years agoxzgrep man page: Document exit statuses.
Lasse Collin [Tue, 19 Jul 2022 20:19:49 +0000 (23:19 +0300)] 
xzgrep man page: Document exit statuses.

3 years agoxzgrep: Improve error handling, especially signals.
Lasse Collin [Tue, 19 Jul 2022 20:13:24 +0000 (23:13 +0300)] 
xzgrep: Improve error handling, especially signals.

xzgrep wouldn't exit on SIGPIPE or SIGQUIT when it clearly
should have. It's quite possible that it's not perfect still
but at least it's much better.

If multiple exit statuses compete, now it tries to pick
the largest of value.

Some comments were added.

The exit status handling of signals is still broken if the shell
uses values larger than 255 in $? to indicate that a process
died due to a signal ***and*** their "exit" command doesn't take
this into account. This seems to work well with the ksh and yash
versions I tried. However, there is a report in gzip/zgrep that
OpenSolaris 5.11 (not 5.10) has a problem with "exit" truncating
the argument to 8 bits:

    https://debbugs.gnu.org/cgi/bugreport.cgi?bug=22900#25

Such a bug would break xzgrep but I didn't add a workaround
at least for now. 5.11 is old and I don't know if the problem
exists in modern descendants, or if the problem exists in other
ksh implementations in use.

3 years agoxzgrep: Make the fix for ZDI-CAN-16587 more robust.
Lasse Collin [Mon, 18 Jul 2022 21:10:55 +0000 (00:10 +0300)] 
xzgrep: Make the fix for ZDI-CAN-16587 more robust.

I don't know if this can make a difference in the real world
but it looked kind of suspicious (what happens with sed
implementations that cannot process very long lines?).
At least this commit shouldn't make it worse.

3 years agoxzgrep: Use grep -H --label when available (GNU, *BSDs).
Lasse Collin [Mon, 18 Jul 2022 18:52:31 +0000 (21:52 +0300)] 
xzgrep: Use grep -H --label when available (GNU, *BSDs).

It avoids the use of sed for prefixing filenames to output lines.
Using sed for that is slower and prone to security bugs so now
the sed method is only used as a fallback.

This also fixes an actual bug: When grepping a binary file,
GNU grep nowadays prints its diagnostics to stderr instead of
stdout and thus the sed-method for prefixing the filename doesn't
work. So with this commit grepping binary files gives reasonable
output with GNU grep now.

This was inspired by zgrep but the implementation is different.

3 years agoxzgrep: Use -e to specify the pattern to grep.
Lasse Collin [Mon, 18 Jul 2022 18:10:25 +0000 (21:10 +0300)] 
xzgrep: Use -e to specify the pattern to grep.

Now we don't need the separate test for adding the -q option
as it can be added directly in the two places where it's needed.

3 years agoScripts: Use printf instead of echo in a few places.
Lasse Collin [Mon, 18 Jul 2022 16:18:48 +0000 (19:18 +0300)] 
Scripts: Use printf instead of echo in a few places.

It's a good habbit as echo has some portability corner cases
when the string contents can be anything.

3 years agoxzgrep: Add more LC_ALL=C to avoid bugs with multibyte characters.
Lasse Collin [Sun, 17 Jul 2022 18:36:25 +0000 (21:36 +0300)] 
xzgrep: Add more LC_ALL=C to avoid bugs with multibyte characters.

Also replace one use of expr with printf.

The rationale for LC_ALL=C was already mentioned in
69d1b3fc29677af8ade8dc15dba83f0589cb63d6 that fixed a security
issue. However, unrelated uses weren't changed in that commit yet.

POSIX says that with sed and such tools one should use LC_ALL=C
to ensure predictable behavior when strings contain byte sequences
that aren't valid multibyte characters in the current locale. See
under "Application usage" in here:

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html

With GNU sed invalid multibyte strings would work without this;
it's documented in its Texinfo manual. Some other implementations
aren't so forgiving.

3 years agoxzgrep: Fix parsing of certain options.
Lasse Collin [Sun, 17 Jul 2022 17:55:16 +0000 (20:55 +0300)] 
xzgrep: Fix parsing of certain options.

Fix handling of "xzgrep -25 foo" (in GNU grep "grep -25 foo" is
an alias for "grep -C25 foo"). xzgrep would treat "foo" as filename
instead of as a pattern. This bug was fixed in zgrep in gzip in 2012.

Add -E, -F, -G, and -P to the "no argument required" list.

Add -X to "argument required" list. It is an
intentionally-undocumented GNU grep option so this isn't
an important option for xzgrep but it seems that other grep
implementations (well, those that I checked) don't support -X
so I hope this change is an improvement still.

grep -d (grep --directories=ACTION) requires an argument. In
contrast to zgrep, I kept -d in the "no argument required" list
because it's not supported in xzgrep (or zgrep). This way
"xzgrep -d" gives an error about option being unsupported instead
of telling that it requires an argument. Both zgrep and xzgrep
tell that it's unsupported if an argument is specified.

Add comments.

3 years agoTests: Add the .lzma files to test_files.sh.
Lasse Collin [Thu, 14 Jul 2022 17:33:05 +0000 (20:33 +0300)] 
Tests: Add the .lzma files to test_files.sh.

3 years agoTests: Add .lzma test files.
Lasse Collin [Thu, 14 Jul 2022 16:37:42 +0000 (19:37 +0300)] 
Tests: Add .lzma test files.

3 years agoliblzma: Rename a variable and improve a comment.
Lasse Collin [Thu, 14 Jul 2022 15:12:38 +0000 (18:12 +0300)] 
liblzma: Rename a variable and improve a comment.

3 years agoUpdate THANKS.
Lasse Collin [Wed, 13 Jul 2022 19:24:41 +0000 (22:24 +0300)] 
Update THANKS.

3 years agoliblzma: Add optional autodetection of LZMA end marker.
Lasse Collin [Wed, 13 Jul 2022 19:24:07 +0000 (22:24 +0300)] 
liblzma: Add optional autodetection of LZMA end marker.

Turns out that this is needed for .lzma files as the spec in
LZMA SDK says that end marker may be present even if the size
is stored in the header. Such files are rare but exist in the
real world. The code in liblzma is so old that the spec didn't
exist in LZMA SDK back then and I had understood that such
files weren't possible (the lzma tool in LZMA SDK didn't
create such files).

This modifies the internal API so that LZMA decoder can be told
if EOPM is allowed even when the uncompressed size is known.
It's allowed with .lzma and not with other uses.

Thanks to Karl Beldan for reporting the problem.

3 years agoxz: Document the special memlimit case of 2000 MiB on MIPS32.
Lasse Collin [Tue, 12 Jul 2022 15:53:04 +0000 (18:53 +0300)] 
xz: Document the special memlimit case of 2000 MiB on MIPS32.

See commit fc3d3a7296ef58bb799a73943636b8bfd95339f7.

3 years agoCreated script to generate code coverage reports.
Jia Tan [Fri, 1 Jul 2022 13:19:26 +0000 (21:19 +0800)] 
Created script to generate code coverage reports.

The script uses lcov and genhtml after running the tests
to show the code coverage statistics. The script will create
a coverage directory where it is run. It can be run both in
and out of the source directory.

3 years agoTests: Add more tests into test_check.
Jia Tan [Thu, 16 Jun 2022 14:32:19 +0000 (17:32 +0300)] 
Tests: Add more tests into test_check.

3 years agoTests: Use char[][24] array for enum_strings_lzma_ret.
Lasse Collin [Thu, 16 Jun 2022 12:02:57 +0000 (15:02 +0300)] 
Tests: Use char[][24] array for enum_strings_lzma_ret.

Array of pointers to short strings is a bit pointless here
and now it's fully const.

3 years agoTests: tuktest.h: Add tuktest_error_impl to help with error conditions.
Lasse Collin [Thu, 16 Jun 2022 11:12:14 +0000 (14:12 +0300)] 
Tests: tuktest.h: Add tuktest_error_impl to help with error conditions.

3 years agoTests: tuktest.h: Rename file_from_* and use tuktest_malloc there.
Lasse Collin [Thu, 16 Jun 2022 10:29:59 +0000 (13:29 +0300)] 
Tests: tuktest.h: Rename file_from_* and use tuktest_malloc there.

3 years agoTests: tuktest.h: Add malloc wrapper with automatic freeing.
Lasse Collin [Thu, 16 Jun 2022 10:08:19 +0000 (13:08 +0300)] 
Tests: tuktest.h: Add malloc wrapper with automatic freeing.

3 years agoTests: tuktest.h: Move a function.
Lasse Collin [Thu, 16 Jun 2022 08:47:37 +0000 (11:47 +0300)] 
Tests: tuktest.h: Move a function.

3 years agoTests: test_vli: Remove an invalid test-assertion.
Lasse Collin [Tue, 14 Jun 2022 19:21:15 +0000 (22:21 +0300)] 
Tests: test_vli: Remove an invalid test-assertion.

lzma_vli is unsigned so trying a signed value results in
a compiler warning from -Wsign-conversion. (lzma_vli)-1
equals to LZMA_VLI_UNKNOWN anyway which is the next assertion.

3 years agoTests: test_vli: Add const where appropriate.
Lasse Collin [Tue, 14 Jun 2022 19:10:10 +0000 (22:10 +0300)] 
Tests: test_vli: Add const where appropriate.

3 years agoAdded vli tests to .gitignore
Jia Tan [Mon, 13 Jun 2022 12:27:03 +0000 (20:27 +0800)] 
Added vli tests to .gitignore

3 years agoCreated tests for all functions exported in vli.h
Jia Tan [Sun, 12 Jun 2022 03:31:40 +0000 (11:31 +0800)] 
Created tests for all functions exported in vli.h

Achieved 100% code coverage vli_encoder.c, vli_decoder.c, and vli_size.c

3 years agoAdded parallel test artifacts to .gitignore
jiat75 [Fri, 3 Jun 2022 13:24:54 +0000 (21:24 +0800)] 
Added parallel test artifacts to .gitignore

3 years agoTests: Use good-1-empty-bcj-lzma2.xz in test_bcj_exact_size.
Lasse Collin [Tue, 14 Jun 2022 18:29:21 +0000 (21:29 +0300)] 
Tests: Use good-1-empty-bcj-lzma2.xz in test_bcj_exact_size.

It's much nicer this way so that the test data isn't a hardcoded
table inside the C file.

3 years agoTests: Add file reading helpers to tuktest.h.
Lasse Collin [Tue, 14 Jun 2022 18:26:13 +0000 (21:26 +0300)] 
Tests: Add file reading helpers to tuktest.h.

3 years agoTests: tuktest.h: Move a printf from a macro to a helper function.
Lasse Collin [Tue, 14 Jun 2022 15:21:57 +0000 (18:21 +0300)] 
Tests: tuktest.h: Move a printf from a macro to a helper function.

3 years agoTests: Add test file good-1-empty-bcj-lzma2.xz.
Lasse Collin [Tue, 14 Jun 2022 14:20:49 +0000 (17:20 +0300)] 
Tests: Add test file good-1-empty-bcj-lzma2.xz.

This is from test_bcj_exact_size.c.
It's good to have it as a standalone file.

3 years agoTests: Created tests for hardware functions.
Jia Tan [Fri, 10 Jun 2022 13:35:18 +0000 (21:35 +0800)] 
Tests: Created tests for hardware functions.

Created tests for all API functions exported in
src/liblzma/api/lzma/hardware.h. The tests are fairly trivial
but are helpful because they will inform users if their machines
cannot support these functions. They also improve the code
coverage metrics.

3 years agoTests: Convert test_check to tuktest.
Lasse Collin [Thu, 2 Jun 2022 18:01:45 +0000 (21:01 +0300)] 
Tests: Convert test_check to tuktest.

Thanks to Jia Tan for help with all the tests.

3 years agoTests: Convert test_block_header to tuktest.
Lasse Collin [Thu, 2 Jun 2022 17:31:03 +0000 (20:31 +0300)] 
Tests: Convert test_block_header to tuktest.

3 years agoTests: Convert test_bcj_exact_size to tuktest.
Lasse Collin [Thu, 2 Jun 2022 17:28:23 +0000 (20:28 +0300)] 
Tests: Convert test_bcj_exact_size to tuktest.

The compress() and decompress() functions were merged because
the later depends on the former so they need to be a single
test case.

3 years agoTests: Include tuktest.h in tests.h.
Lasse Collin [Thu, 2 Jun 2022 17:27:00 +0000 (20:27 +0300)] 
Tests: Include tuktest.h in tests.h.

This breaks -Werror because none of the tests so far use
tuktest.h and thus there are warnings about unused variables
and functions.

3 years agoTests: Add tuktest.h mini-test-framework.
Lasse Collin [Thu, 2 Jun 2022 17:25:21 +0000 (20:25 +0300)] 
Tests: Add tuktest.h mini-test-framework.

3 years agoBuild: Enable Automake's parallel test harness.
Lasse Collin [Mon, 23 May 2022 18:31:36 +0000 (21:31 +0300)] 
Build: Enable Automake's parallel test harness.

It has been the default for quite some time already and
the old serial harness isn't discouraged. The downside is
that with parallel tests one cannot print progress info or
other diagnostics to the terminal; all output from the tests
will be in the log files only. But now that the compression
tests are separated the parallel tests will speed things up.

3 years agoTests: Split test_compress.sh into separate test unit for each file.
Lasse Collin [Mon, 23 May 2022 18:17:47 +0000 (21:17 +0300)] 
Tests: Split test_compress.sh into separate test unit for each file.

test_compress.sh now takes one command line argument:
a filename to be tested. If it begins with "compress_generated_"
the file will be created with create_compress_files.

This will allow parallel execution of the slow tests.

3 years agoTest: Make create_compress_files.c a little more flexible.
Lasse Collin [Mon, 23 May 2022 17:32:49 +0000 (20:32 +0300)] 
Test: Make create_compress_files.c a little more flexible.

If a command line argument is given, then only the test file
of that type is created. It's quite dumb in sense that unknown
names don't give an error but it's good enough here.

Also use EXIT_FAILURE instead of 1 as exit status for errors.

3 years agoTests: Remove unneeded commented lines from test_compress.sh.
Lasse Collin [Mon, 23 May 2022 17:17:42 +0000 (20:17 +0300)] 
Tests: Remove unneeded commented lines from test_compress.sh.

3 years agoTests: Remove progress indicator from test_compress.sh.
Lasse Collin [Mon, 23 May 2022 17:16:00 +0000 (20:16 +0300)] 
Tests: Remove progress indicator from test_compress.sh.

It will be useless with Automake's parallel tests.

3 years agoliblzma: Silence a warning.
Lasse Collin [Mon, 23 May 2022 16:37:18 +0000 (19:37 +0300)] 
liblzma: Silence a warning.

The actual initialization is done via mythread_sync and seems
that GCC doesn't necessarily see that it gets initialized there.

3 years agoxz: Fix build with --disable-threads.
Lasse Collin [Thu, 14 Apr 2022 17:53:16 +0000 (20:53 +0300)] 
xz: Fix build with --disable-threads.

3 years agoxz: Change the cap of the default -T0 memlimit for 32-bit xz.
Lasse Collin [Thu, 14 Apr 2022 11:50:17 +0000 (14:50 +0300)] 
xz: Change the cap of the default -T0 memlimit for 32-bit xz.

The SIZE_MAX / 3 was 1365 MiB. 1400 MiB gives little more room
and it looks like a round (artificial) number in --info-memory
once --info-memory is made to display it.

Also, using #if avoids useless code on 64-bit builds.

3 years agoxz: Add a default soft memory usage limit for --threads=0.
Lasse Collin [Thu, 14 Apr 2022 11:20:46 +0000 (14:20 +0300)] 
xz: Add a default soft memory usage limit for --threads=0.

This is a soft limit in sense that it only affects the number of
threads. It never makes xz fail and it never makes xz change
settings that would affect the compressed output.

The idea is to make -T0 have more reasonable behavior when
the system has very many cores or when a memory-hungry
compression options are used. This also helps with 32-bit xz,
preventing it from running out of address space.

The downside of this commit is that now the number of threads
might become too low compared to what the user expected. I
hope this to be an acceptable compromise as the old behavior
has been a source of well-argued complaints for a long time.

3 years agoxz: Make -T0 use multithreaded mode on single-core systems.
Lasse Collin [Thu, 14 Apr 2022 09:59:09 +0000 (12:59 +0300)] 
xz: Make -T0 use multithreaded mode on single-core systems.

The main problem withi the old behavior is that the compressed
output is different on single-core systems vs. multicore systems.
This commit fixes it by making -T0 one thread in multithreaded mode
on single-core systems.

The downside of this is that it uses more memory. However, if
--memlimit-compress is used, xz can (thanks to the previous commit)
drop to the single-threaded mode still.