]> git.ipfire.org Git - thirdparty/xz.git/log
thirdparty/xz.git
18 months agoTests: Use smaller dictionary size in RISC-V test files.
Jia Tan [Tue, 23 Jan 2024 15:52:14 +0000 (23:52 +0800)] 
Tests: Use smaller dictionary size in RISC-V test files.

18 months agoTests: Skip RISC-V test files if decoder was not built.
Jia Tan [Tue, 23 Jan 2024 15:50:57 +0000 (23:50 +0800)] 
Tests: Skip RISC-V test files if decoder was not built.

18 months agoxz: Man page: Add more examples of LZMA2 options with BCJ filters.
Lasse Collin [Tue, 23 Jan 2024 14:11:54 +0000 (16:11 +0200)] 
xz: Man page: Add more examples of LZMA2 options with BCJ filters.

18 months agoliblzma: RISC-V filter: Use byte-by-byte access.
Lasse Collin [Mon, 22 Jan 2024 22:09:48 +0000 (00:09 +0200)] 
liblzma: RISC-V filter: Use byte-by-byte access.

Not all RISC-V processors support fast unaligned access so
it's better to read only one byte in the main loop. This can
be faster even on x86-64 when compared to reading 32 bits at
a time as half the time the address is only 16-bit aligned.

The downside is larger code size on archs that do support
fast unaligned access.

18 months agoxz: Update xz -lvv for RISC-V filter.
Jia Tan [Mon, 22 Jan 2024 15:33:39 +0000 (23:33 +0800)] 
xz: Update xz -lvv for RISC-V filter.

Version 5.6.0 will be shown, even though upcoming alphas and betas
will be able to support this filter. 5.6.0 looks nicer in the output and
people shouldn't be encouraged to use an unstable version in production
in any way.

18 months agoTests: Add two RISC-V Filter test files.
Jia Tan [Mon, 22 Jan 2024 15:33:39 +0000 (23:33 +0800)] 
Tests: Add two RISC-V Filter test files.

These test files achieve 100% code coverage in
src/liblzma/simple/riscv.c. They contain all of the instructions that
should be filtered and a few cases that should not.

18 months agoxz: Update message in --long-help for RISC-V Filter.
Jia Tan [Mon, 22 Jan 2024 15:33:39 +0000 (23:33 +0800)] 
xz: Update message in --long-help for RISC-V Filter.

18 months agoxz: Update the man page for the RISC-V Filter.
Jia Tan [Mon, 22 Jan 2024 15:33:39 +0000 (23:33 +0800)] 
xz: Update the man page for the RISC-V Filter.

A special note was added to suggest using four-byte alignment when the
compressed instruction extension is not present in a RISC-V binary.

18 months agoTests: Add RISC-V Filter test in test_compress.sh.
Jia Tan [Mon, 22 Jan 2024 15:33:39 +0000 (23:33 +0800)] 
Tests: Add RISC-V Filter test in test_compress.sh.

18 months agoliblzma: Update string_conversion.c to support RISC-V Filter.
Jia Tan [Mon, 22 Jan 2024 15:33:39 +0000 (23:33 +0800)] 
liblzma: Update string_conversion.c to support RISC-V Filter.

18 months agoCMake: Support RISC-V BCJ Filter for encoding and decoding.
Jia Tan [Mon, 22 Jan 2024 15:33:39 +0000 (23:33 +0800)] 
CMake: Support RISC-V BCJ Filter for encoding and decoding.

18 months agoliblzma: Add RISC-V BCJ filter.
Jia Tan [Mon, 22 Jan 2024 15:33:39 +0000 (23:33 +0800)] 
liblzma: Add RISC-V BCJ filter.

The new Filter ID is 0x0B.

Thanks to Chien Wong <m@xv97.com> for the initial version of the Filter,
the xz CLI updates, and the Autotools build system modifications.

Thanks to Igor Pavlov for his many contributions to the design of
the filter.

18 months agoDocs: Update .xz file format specification to 1.2.0.
Jia Tan [Fri, 19 Jan 2024 15:08:14 +0000 (23:08 +0800)] 
Docs: Update .xz file format specification to 1.2.0.

The new RISC-V filter was added to the specification, in addition to
updating the specification URL.

18 months agoxz: Update website URLs in the man pages.
Jia Tan [Fri, 19 Jan 2024 15:08:14 +0000 (23:08 +0800)] 
xz: Update website URLs in the man pages.

18 months agoliblzma: Update website URL.
Jia Tan [Fri, 19 Jan 2024 15:08:14 +0000 (23:08 +0800)] 
liblzma: Update website URL.

18 months agoDocs: Update website URLs.
Jia Tan [Fri, 19 Jan 2024 15:08:14 +0000 (23:08 +0800)] 
Docs: Update website URLs.

18 months agoBuild: Update website URL.
Jia Tan [Fri, 19 Jan 2024 15:08:14 +0000 (23:08 +0800)] 
Build: Update website URL.

18 months agoliblzma: CRC: Add a comment to crc_x86_clmul.h about BUILDING_ macros.
Lasse Collin [Thu, 11 Jan 2024 13:01:50 +0000 (15:01 +0200)] 
liblzma: CRC: Add a comment to crc_x86_clmul.h about BUILDING_ macros.

18 months agoliblzma: CRC: Remove crc_always_inline, use lzma_always_inline instead.
Lasse Collin [Thu, 11 Jan 2024 13:22:36 +0000 (15:22 +0200)] 
liblzma: CRC: Remove crc_always_inline, use lzma_always_inline instead.

Now crc_simd_body() in crc_x86_clmul.h is only called once
in a translation unit, we no longer need to be so cautious
about ensuring the always-inline behavior.

18 months agoliblzma: CRC: Update CLMUL comments to more generic wording.
Lasse Collin [Thu, 11 Jan 2024 12:39:46 +0000 (14:39 +0200)] 
liblzma: CRC: Update CLMUL comments to more generic wording.

18 months agoliblzma: Rename arch-specific CRC functions and macros.
Lasse Collin [Wed, 10 Jan 2024 16:23:31 +0000 (18:23 +0200)] 
liblzma: Rename arch-specific CRC functions and macros.

CRC_CLMUL was split to CRC_ARCH_OPTIMIZED and CRC_X86_CLMUL.
CRC_ARCH_OPTIMIZED is defined when an arch-optimized version is used.
Currently the x86 CLMUL implementations are the only arch-optimized
versions, and these also use the CRC_x86_CLMUL macro to tell when
crc_x86_clmul.h needs to be included.

is_clmul_supported() was renamed to is_arch_extension_supported().
crc32_clmul() and crc64_clmul() were renamed to
crc32_arch_optimized() and crc64_arch_optimized().
This way the names make sense with arch-specific non-CLMUL
implementations as well.

18 months agoliblzma: Fix a comment in crc_common.h.
Lasse Collin [Wed, 10 Jan 2024 16:19:21 +0000 (18:19 +0200)] 
liblzma: Fix a comment in crc_common.h.

18 months agoliblzma: Avoid extern lzma_crc32_clmul() and lzma_crc64_clmul().
Lasse Collin [Fri, 20 Oct 2023 20:35:10 +0000 (23:35 +0300)] 
liblzma: Avoid extern lzma_crc32_clmul() and lzma_crc64_clmul().

A CLMUL-only build will have the crcxx_clmul() inlined into
lzma_crcxx(). Previously a jump to the extern lzma_crcxx_clmul()
was needed. Notes about shared liblzma on ELF platforms:

  - On platforms that support ifunc and -fvisibility=hidden, this
    was silly because CLMUL-only build would have that single extra
    jump instruction of extra overhead.

  - On platforms that support neither -fvisibility=hidden nor linker
    version script (liblzma*.map), jumping to lzma_crcxx_clmul()
    would go via PLT so a few more instructions of overhead (still
    not a big issue but silly nevertheless).

There was a downside with static liblzma too: if an application only
needs lzma_crc64(), static linking would make the linker include the
CLMUL code for both CRC32 and CRC64 from crc_x86_clmul.o even though
the CRC32 code wouldn't be needed, thus increasing code size of the
executable (assuming that -ffunction-sections isn't used).

Also, now compilers are likely to inline crc_simd_body()
even if they don't support the always_inline attribute
(or MSVC's __forceinline). Quite possibly all compilers
that build the code do support such an attribute. But now
it likely isn't a problem even if the attribute wasn't supported.

Now all x86-specific stuff is in crc_x86_clmul.h. If other archs
The other archs can then have their own headers with their own
is_clmul_supported() and crcxx_clmul().

Another bonus is that the build system doesn't need to care if
crc_clmul.c is needed.

is_clmul_supported() stays as inline function as it's not needed
when doing a CLMUL-only build (avoids a warning about unused function).

18 months agoliblzma: crc_clmul.c: Add crc_attr_target macro.
Lasse Collin [Fri, 20 Oct 2023 21:06:52 +0000 (00:06 +0300)] 
liblzma: crc_clmul.c: Add crc_attr_target macro.

This reduces the number of the complex #if directives.

18 months agoliblzma: Simplify existing cases with lzma_attr_no_sanitize_address.
Lasse Collin [Fri, 20 Oct 2023 19:49:48 +0000 (22:49 +0300)] 
liblzma: Simplify existing cases with lzma_attr_no_sanitize_address.

18 months agoliblzma: #define crc_attr_no_sanitize_address in crc_common.h.
Lasse Collin [Fri, 20 Oct 2023 18:53:35 +0000 (21:53 +0300)] 
liblzma: #define crc_attr_no_sanitize_address in crc_common.h.

18 months agoliblzma: CRC: Add empty lines.
Lasse Collin [Fri, 20 Oct 2023 20:25:14 +0000 (23:25 +0300)] 
liblzma: CRC: Add empty lines.

And remove one too.

18 months agoliblzma: crc_clmul.c: Tidy up the location of MSVC pragma.
Lasse Collin [Fri, 20 Oct 2023 20:19:33 +0000 (23:19 +0300)] 
liblzma: crc_clmul.c: Tidy up the location of MSVC pragma.

It makes no difference in practice.

19 months agoUpdate THANKS.
Lasse Collin [Wed, 20 Dec 2023 19:16:24 +0000 (21:16 +0200)] 
Update THANKS.

19 months agoliblzma: Use 8-byte method in memcmplen.h on ARM64.
Lasse Collin [Wed, 20 Dec 2023 19:15:16 +0000 (21:15 +0200)] 
liblzma: Use 8-byte method in memcmplen.h on ARM64.

It requires fast unaligned access to 64-bit integers
and a fast instruction to count leading zeros in
a 64-bit integer (__builtin_ctzll()). This perhaps
should be enabled on some other archs too.

Thanks to Chenxi Mao for the original patch:
https://github.com/tukaani-project/xz/pull/75 (the first commit)
According to the numbers there, this may improve encoding
speed by about 3-5 %.

This enables the 8-byte method on MSVC ARM64 too which
should work but wasn't tested.

19 months agoliblzma: Check also for __clang__ in memcmplen.h.
Lasse Collin [Wed, 20 Dec 2023 19:01:06 +0000 (21:01 +0200)] 
liblzma: Check also for __clang__ in memcmplen.h.

This change hopefully makes no practical difference as Clang
likely was detected via __GNUC__ or _MSC_VER already.

19 months agoTranslations: Update the French translation.
Jia Tan [Thu, 21 Dec 2023 13:39:08 +0000 (21:39 +0800)] 
Translations: Update the French translation.

19 months agoxz: Add a comment to Capsicum sandbox setup.
Jia Tan [Thu, 21 Dec 2023 08:39:53 +0000 (16:39 +0800)] 
xz: Add a comment to Capsicum sandbox setup.

This comment is repeated in xzdec.c to help remind us why all the
capabilities are removed from stdin in certain situations.

19 months agoDocs: Update --enable-sandbox option in INSTALL.
Jia Tan [Wed, 20 Dec 2023 14:19:19 +0000 (22:19 +0800)] 
Docs: Update --enable-sandbox option in INSTALL.

xzdec now also uses the sandbox when its configured.

19 months agoCMake: Move sandbox detection outside of xz section.
Jia Tan [Wed, 20 Dec 2023 14:39:13 +0000 (22:39 +0800)] 
CMake: Move sandbox detection outside of xz section.

The sandbox is now enabled for xzdec as well, so it no longer belongs
in just the xz section. xz and xzdec are always built, except for older
MSVC versions, so there isn't a need to conditionally show the sandbox
configuration. CMake will do a little unecessary work on older MSVC
versions that can't build xz or xzdec, but this is a very small
downside.

19 months agoBuild: Allow sandbox to be configured for just xzdec.
Jia Tan [Wed, 20 Dec 2023 14:43:44 +0000 (22:43 +0800)] 
Build: Allow sandbox to be configured for just xzdec.

If xz is disabled, then xzdec can still use the sandbox.

19 months agoxzdec: Add sandbox support for Pledge, Capsicum, and Landlock.
Jia Tan [Tue, 19 Dec 2023 13:18:28 +0000 (21:18 +0800)] 
xzdec: Add sandbox support for Pledge, Capsicum, and Landlock.

A very strict sandbox is used when the last file is decompressed. The
likely most common use case of xzdec is to decompress a single file.
The Pledge sandbox is applied to the entire process with slightly more
relaxed promises, until the last file is processed.

Thanks to Christian Weisgerber for the initial patch adding Pledge
sandboxing.

19 months agoliblzma: Initialize lzma_lz_encoder pointers with NULL.
Jia Tan [Wed, 20 Dec 2023 13:31:34 +0000 (21:31 +0800)] 
liblzma: Initialize lzma_lz_encoder pointers with NULL.

This fixes the recent change to lzma_lz_encoder that used memzero
instead of the NULL constant. On some compilers the NULL constant
(always 0) may not equal the NULL pointer (this only needs to guarentee
to not point to valid memory address).

Later code compares the pointers to the NULL pointer so we must
initialize them with the NULL pointer instead of 0 to guarentee
code correctness.

19 months agoliblzma: Set all values in lzma_lz_encoder to NULL after allocation.
Jia Tan [Sat, 16 Dec 2023 12:51:38 +0000 (20:51 +0800)] 
liblzma: Set all values in lzma_lz_encoder to NULL after allocation.

The first member of lzma_lz_encoder doesn't necessarily need to be set
to NULL since it will always be set before anything tries to use it.
However the function pointer members must be set to NULL since other
functions rely on this NULL value to determine if this behavior is
supported or not.

This fixes a somewhat serious bug, where the options_update() and
set_out_limit() function pointers are not set to NULL. This seems to
have been forgotten since these function pointers were added many years
after the original two (code() and end()).

The problem is that by not setting this to NULL we are relying on the
memory allocation to zero things out if lzma_filters_update() is called
on a LZMA1 encoder. The function pointer for set_out_limit() is less
serious because there is not an API function that could call this in an
incorrect way. set_out_limit() is only called by the MicroLZMA encoder,
which must use LZMA1 where set_out_limit() is always set. Its currently
not possible to call set_out_limit() on an LZMA2 encoder at this time.

So calling lzma_filters_update() on an LZMA1 encoder had undefined
behavior since its possible that memory could be manipulated so the
options_update member pointed to a different instruction sequence.

This is unlikely to be a bug in an existing application since it relies
on calling lzma_filters_update() on an LZMA1 encoder in the first place.
For instance, it does not affect xz because lzma_filters_update() can
only be used when encoding to the .xz format.

This is fixed by using memzero() to set all members of lzma_lz_encoder
to NULL after it is allocated. This ensures this mistake will not occur
here in the future if any additional function pointers are added.

19 months agoliblzma: Tweak a comment.
Jia Tan [Sat, 16 Dec 2023 12:30:55 +0000 (20:30 +0800)] 
liblzma: Tweak a comment.

19 months agoliblzma: Make parameter names in function definition match declaration.
Jia Tan [Sat, 16 Dec 2023 12:28:21 +0000 (20:28 +0800)] 
liblzma: Make parameter names in function definition match declaration.

lzma_raw_encoder() and lzma_raw_encoder_init() used "options" as the
parameter name instead of "filters" (used by the declaration). "filters"
is more clear since the parameter represents the list of filters passed
to the raw encoder, each of which contains filter options.

19 months agoliblzma: Improve lzma encoder init function consistency.
Jia Tan [Sat, 16 Dec 2023 12:18:47 +0000 (20:18 +0800)] 
liblzma: Improve lzma encoder init function consistency.

lzma_encoder_init() did not check for NULL options, but
lzma2_encoder_init() did. This is more of a code style improvement than
anything else to help make lzma_encoder_init() and lzma2_encoder_init()
more similar.

19 months agoDocs: Update repository URL in Changelog.
Jia Tan [Sat, 16 Dec 2023 03:20:20 +0000 (11:20 +0800)] 
Docs: Update repository URL in Changelog.

19 months agoCI: Update Upload Artifact Action.
Jia Tan [Fri, 15 Dec 2023 08:56:31 +0000 (16:56 +0800)] 
CI: Update Upload Artifact Action.

19 months agoTests: Silence -Wsign-conversion warning on GCC version < 10.
Jia Tan [Thu, 7 Dec 2023 13:48:07 +0000 (21:48 +0800)] 
Tests: Silence -Wsign-conversion warning on GCC version < 10.

Since GCC version 10, GCC no longer complains about simple implicit
integer conversions with Arithmetic operators.

For instance:

    uint8_t a = 5;
    uint32_t b = a + 5;

Give a warning on GCC 9 and earlier but this:

    uint8_t a = 5;
    uint32_t b = (a + 5) * 2;

Gives a warning with GCC 10+.

19 months agoUpdate THANKS.
Jia Tan [Wed, 6 Dec 2023 10:39:03 +0000 (18:39 +0800)] 
Update THANKS.

19 months agoTests: Minor cleanups to OSS-Fuzz files.
Jia Tan [Wed, 6 Dec 2023 10:30:25 +0000 (18:30 +0800)] 
Tests: Minor cleanups to OSS-Fuzz files.

Most of these fixes are small typos and tweaks. A few were caused by bad
advice from me. Here is the summary of what is changed:

- Author line edits

- Small comment changes/additions

- Using the return value in the error messages in the fuzz targets'
  coder initialization code

- Removed fuzz_encode_stream.options. This set a max length, which may
  prevent some worthwhile code paths from being properly exercised.

- Removed the max_len option from fuzz_decode_stream.options for the
  same reason as fuzz_encode_stream. The alone decoder fuzz target still
  has this restriction.

- Altered the dictionary contents for fuzz_lzma.dict. Instead of keeping
  the properties static and varying the dictionary size, the properties
  are varied and the dictionary size is kept small. The dictionary size
  doesn't have much impact on the code paths but the properties do.

Closes: https://github.com/tukaani-project/xz/pull/73
19 months agoTests: Add fuzz_encode_stream ossfuzz target.
Maksym Vatsyk [Tue, 5 Dec 2023 15:31:09 +0000 (16:31 +0100)] 
Tests: Add fuzz_encode_stream ossfuzz target.

This fuzz target handles .xz stream encoding. The first byte of input
is used to dynamically set the preset level in order to increase the
fuzz coverage of complex critical code paths.

19 months agoTests: Add fuzz_decode_alone OSS-Fuzz target
Maksym Vatsyk [Mon, 4 Dec 2023 16:23:24 +0000 (17:23 +0100)] 
Tests: Add fuzz_decode_alone OSS-Fuzz target

This fuzz target that handles LZMA alone decoding. A new fuzz
dictionary .dict was also created with common LZMA header values to
help speed up the discovery of valid headers.

19 months agoTests: Update OSS-Fuzz Makefile.
Maksym Vatsyk [Mon, 4 Dec 2023 16:21:29 +0000 (17:21 +0100)] 
Tests: Update OSS-Fuzz Makefile.

All .c files can be built as separate fuzz targets. This simplifies
the Makefile by allowing us to use wildcards instead of having a
Makefile target for each fuzz target.

19 months agoTests: Move common OSS-Fuzz target code to .h file.
Maksym Vatsyk [Mon, 4 Dec 2023 16:20:08 +0000 (17:20 +0100)] 
Tests: Move common OSS-Fuzz target code to .h file.

19 months agoTests: Rename OSS-Fuzz files.
Maksym Vatsyk [Mon, 4 Dec 2023 16:18:20 +0000 (17:18 +0100)] 
Tests: Rename OSS-Fuzz files.

20 months agoUpdate THANKS.
Jia Tan [Thu, 30 Nov 2023 15:10:43 +0000 (23:10 +0800)] 
Update THANKS.

20 months agoTests: Fix typos
Kian-Meng Ang [Thu, 30 Nov 2023 15:01:19 +0000 (23:01 +0800)] 
Tests: Fix typos

20 months agoxz: Fix typo
Kian-Meng Ang [Thu, 30 Nov 2023 14:59:47 +0000 (22:59 +0800)] 
xz: Fix typo

20 months agoUpdate THANKS.
Jia Tan [Thu, 30 Nov 2023 12:41:00 +0000 (20:41 +0800)] 
Update THANKS.

20 months agoCI: Test musl libc builds on Ubuntu runner.
Jia Tan [Wed, 22 Nov 2023 13:20:12 +0000 (21:20 +0800)] 
CI: Test musl libc builds on Ubuntu runner.

20 months agoCI: Allow ci_build.sh to set a different C compiler.
Jia Tan [Wed, 22 Nov 2023 13:12:15 +0000 (21:12 +0800)] 
CI: Allow ci_build.sh to set a different C compiler.

20 months agoCMake: Use consistent indentation with check_c_source_compiles().
Jia Tan [Fri, 24 Nov 2023 13:19:12 +0000 (21:19 +0800)] 
CMake: Use consistent indentation with check_c_source_compiles().

20 months agoCMake: Change __attribute__((__ifunc__())) detection.
Jia Tan [Wed, 22 Nov 2023 12:33:36 +0000 (20:33 +0800)] 
CMake: Change __attribute__((__ifunc__())) detection.

This renames ALLOW_ATTR_IFUNC to USE_ATTR_IFUNC and applies the ifunc
detection changes that were made to the Autotools build.

Fixes: https://github.com/tukaani-project/xz/issues/70
20 months agoDocs: Update INSTALL for --enable_ifunc change.
Jia Tan [Fri, 24 Nov 2023 12:19:11 +0000 (20:19 +0800)] 
Docs: Update INSTALL for --enable_ifunc change.

20 months agoBuild: Change --enable-ifunc handling.
Jia Tan [Tue, 21 Nov 2023 12:56:55 +0000 (20:56 +0800)] 
Build: Change --enable-ifunc handling.

Some compilers support __attribute__((__ifunc__())) even though the
dynamic linker does not. The compiler is able to create the binary
but it will fail on startup. So it is not enough to just test if
the attribute is supported.

The default value for enable_ifunc is now auto, which will attempt
to compile a program using __attribute__((__ifunc__())). There are
additional checks in this program if glibc is being used or if it
is running on FreeBSD.

Setting --enable-ifunc will skip this test and always enable
__attribute__((__ifunc__())), even if is not supported.

20 months agoxz: Tweak a comment.
Lasse Collin [Thu, 23 Nov 2023 15:39:10 +0000 (17:39 +0200)] 
xz: Tweak a comment.

20 months agoxz: Use is_tty() in message.c.
Jia Tan [Thu, 23 Nov 2023 14:13:39 +0000 (22:13 +0800)] 
xz: Use is_tty() in message.c.

20 months agoxz: Create separate is_tty() function.
Jia Tan [Thu, 23 Nov 2023 14:04:35 +0000 (22:04 +0800)] 
xz: Create separate is_tty() function.

The new is_tty() will report if a file descriptor is a terminal or not.
On POSIX systems, it is a wrapper around isatty(). However, the native
Windows implementation of isatty() will return true for all character
devices, not just terminals. So is_tty() has a special case for Windows
so it can use alternative Windows API functions to determine if a file
descriptor is a terminal.

This fixes a bug with MSVC and MinGW-w64 builds that refused to read from
or write to non-terminal character devices because xz thought it was a
terminal. For instance:

    xz foo -c > /dev/null

would fail because /dev/null was assumed to be a terminal.

20 months agotuklib_integer: Fix typo discovered by codespell.
Jia Tan [Wed, 22 Nov 2023 12:39:41 +0000 (20:39 +0800)] 
tuklib_integer: Fix typo discovered by codespell.

Based on internet dictionary searches, 'choise' is an outdated spelling
of 'choice'.

20 months agoxz: Move the check for --suffix with --format=raw a few lines earlier.
Lasse Collin [Fri, 17 Nov 2023 17:35:19 +0000 (19:35 +0200)] 
xz: Move the check for --suffix with --format=raw a few lines earlier.

Now it reads from argv[] instead of args->arg_names.

20 months agoTests: Create test_suffix.sh.
Jia Tan [Fri, 17 Nov 2023 12:35:11 +0000 (20:35 +0800)] 
Tests: Create test_suffix.sh.

This tests some complicated interactions with the --suffix= option.
The suffix option must be used with --format=raw, but can optionally
be used to override the default .xz suffix.

This test also verifies some recent bugs have been correctly solved
and to hopefully avoid further regressions in the future.

20 months agoxz: Fix a bug with --files and --files0 in raw mode without a suffix.
Jia Tan [Fri, 17 Nov 2023 12:19:26 +0000 (20:19 +0800)] 
xz: Fix a bug with --files and --files0 in raw mode without a suffix.

The following command caused a segmentation fault:

    xz -Fraw --lzma1 --files=foo

when foo was a valid file. The usage of --files or --files0 was not
being checked when compressing or decompressing in raw mode without a
suffix. The suffix checking code was meant to validate that all files
to be processed are "-" (if not writing to standard out), meaning the
data is only coming from standard in. In this case, there were no file
names to check since --files and --files0 store their file name in a
different place.

Later code assumed the suffix was set and caused a segmentation fault.
Now, the above command results in an error.

20 months agoTests: Fix typo in a comment.
Jia Tan [Fri, 17 Nov 2023 12:04:58 +0000 (20:04 +0800)] 
Tests: Fix typo in a comment.

20 months agoxz: Refactor suffix test with raw format.
Jia Tan [Wed, 15 Nov 2023 15:40:13 +0000 (23:40 +0800)] 
xz: Refactor suffix test with raw format.

The previous version set opt_stdout, but this caused an issue with
copying an input file to standard out when decompressing an unknown file
type. The following needs to result in an error:

    echo foo | xz -df

since -c, --stdout is not used. This fixes the previous error by not
setting opt_stdout.

20 months agoxz: Move suffix check after stdout mode is detected.
Jia Tan [Tue, 14 Nov 2023 12:27:46 +0000 (20:27 +0800)] 
xz: Move suffix check after stdout mode is detected.

This fixes a bug introduced in cc5aa9ab138beeecaee5a1e81197591893ee9ca0
when the suffix check was initially moved. This caused a situation that
previously worked:

    echo foo | xz -Fraw --lzma1 | wc -c

to fail because the old code knew that this would write to standard out
so a suffix was not needed.

20 months agoxz: Detect when all data will be written to standard out earlier.
Jia Tan [Tue, 14 Nov 2023 12:27:04 +0000 (20:27 +0800)] 
xz: Detect when all data will be written to standard out earlier.

If the -c, --stdout argument is not used, then we can still detect when
the data will be written to standard out if all of the provided
filenames are "-" (denoting standard in) or if no filenames are
provided.

20 months agoliblzma: Add missing comments to lz_encoder.h.
Jia Tan [Wed, 8 Nov 2023 17:21:53 +0000 (01:21 +0800)] 
liblzma: Add missing comments to lz_encoder.h.

21 months agoAdd NEWS for 5.4.5.
Jia Tan [Wed, 1 Nov 2023 12:18:30 +0000 (20:18 +0800)] 
Add NEWS for 5.4.5.

21 months agoliblzma: Fix compilation of fastpos_tablegen.c.
Lasse Collin [Tue, 31 Oct 2023 19:41:09 +0000 (21:41 +0200)] 
liblzma: Fix compilation of fastpos_tablegen.c.

The macro lzma_attr_visibility_hidden has to be defined to make
fastpos.h usable. The visibility attribute is irrelevant to
fastpos_tablegen.c so simply #define the macro to an empty value.

fastpos_tablegen.c is never built by the included build systems
and so the problem wasn't noticed earlier. It's just a standalone
program for generating fastpos_table.c.

Fixes: https://github.com/tukaani-project/xz/pull/69
Thanks to GitHub user Jamaika1.

21 months agoBuild: Fix text wrapping in an output message.
Jia Tan [Tue, 31 Oct 2023 13:51:40 +0000 (21:51 +0800)] 
Build: Fix text wrapping in an output message.

21 months agoliblzma: Add a note why crc_always_inline exists for now.
Lasse Collin [Mon, 30 Oct 2023 16:09:53 +0000 (18:09 +0200)] 
liblzma: Add a note why crc_always_inline exists for now.

Solaris Studio is a possible example (not tested) which
supports the always_inline attribute but might not get
detected by the common.h #ifdefs.

21 months agoliblzma: Use lzma_always_inline in memcmplen.h.
Lasse Collin [Sun, 22 Oct 2023 14:59:11 +0000 (17:59 +0300)] 
liblzma: Use lzma_always_inline in memcmplen.h.

21 months agoliblzma: #define lzma_always_inline in common.h.
Lasse Collin [Mon, 30 Oct 2023 15:43:03 +0000 (17:43 +0200)] 
liblzma: #define lzma_always_inline in common.h.

21 months agoliblzma: Use lzma_attr_visibility_hidden on private extern declarations.
Lasse Collin [Sun, 22 Oct 2023 14:15:32 +0000 (17:15 +0300)] 
liblzma: Use lzma_attr_visibility_hidden on private extern declarations.

These variables are internal to liblzma and not exposed in the API.

21 months agoliblzma: #define lzma_attr_visibility_hidden in common.h.
Lasse Collin [Sun, 22 Oct 2023 14:08:39 +0000 (17:08 +0300)] 
liblzma: #define lzma_attr_visibility_hidden in common.h.

In ELF shared libs:

-fvisibility=hidden affects definitions of symbols but not
declarations.[*] This doesn't affect direct calls to functions
inside liblzma as a linker can replace a call to lzma_foo@plt
with a call directly to lzma_foo when -fvisibility=hidden is used.

[*] It has to be like this because otherwise every installed
    header file would need to explictly set the symbol visibility
    to default.

When accessing extern variables that aren't defined in the
same translation unit, compiler assumes that the variable has
the default visibility and thus indirection is needed. Unlike
function calls, linker cannot optimize this.

Using __attribute__((__visibility__("hidden"))) with the extern
variable declarations tells the compiler that indirection isn't
needed because the definition is in the same shared library.

About 15+ years ago, someone told me that it would be good if
the CRC tables would be defined in the same translation unit
as the C code of the CRC functions. While I understood that it
could help a tiny amount, I didn't want to change the code because
a separate translation unit for the CRC tables was needed for the
x86 assembly code anyway. But when visibility attributes are
supported, simply marking the extern declaration with the
hidden attribute will get identical result. When there are only
a few affected variables, this is trivial to do. I wish I had
understood this back then already.

21 months agoliblzma: Refer to MinGW-w64 instead of MinGW in the API headers.
Lasse Collin [Sat, 30 Sep 2023 19:54:28 +0000 (22:54 +0300)] 
liblzma: Refer to MinGW-w64 instead of MinGW in the API headers.

MinGW (formely a MinGW.org Project, later the MinGW.OSDN Project
at <https://osdn.net/projects/mingw/>) has GCC 9.2.0 as the
most recent GCC package (released 2021-02-02). The project might
still be alive but majority of people have switched to MinGW-w64.
Thus it seems clearer to refer to MinGW-w64 in our API headers too.
Building with MinGW is likely to still work but I haven't tested it
in the recent years.

21 months agoCMake: Use -D_FILE_OFFSET_BITS=64 if (and only if) needed.
Lasse Collin [Tue, 26 Sep 2023 21:58:17 +0000 (00:58 +0300)] 
CMake: Use -D_FILE_OFFSET_BITS=64 if (and only if) needed.

A CMake option LARGE_FILE_SUPPORT is created if and only if
-D_FILE_OFFSET_BITS=64 affects sizeof(off_t).

This is needed on many 32-bit platforms and even with 64-bit builds
with MinGW-w64 to get support for files larger than 2 GiB.

21 months agoCMake: Generate and install liblzma.pc if not using MSVC.
Lasse Collin [Fri, 29 Sep 2023 23:14:25 +0000 (02:14 +0300)] 
CMake: Generate and install liblzma.pc if not using MSVC.

Autotools based build uses -pthread and thus adds it to Libs.private
in liblzma.pc. CMake doesn't use -pthread at all if pthread functions
are available in libc so Libs.private doesn't get -pthread either.

21 months agoCMake: Rearrange the PACKAGE_ variables.
Lasse Collin [Fri, 29 Sep 2023 22:13:13 +0000 (01:13 +0300)] 
CMake: Rearrange the PACKAGE_ variables.

The windres workaround now replaces spaces with \x20 so
the package name isn't repeated.

These changes will help with creation of liblzma.pc.

21 months agoliblzma: Add Cflags.private to liblzma.pc.in for MSYS2.
Lasse Collin [Fri, 29 Sep 2023 17:46:11 +0000 (20:46 +0300)] 
liblzma: Add Cflags.private to liblzma.pc.in for MSYS2.

It properly adds -DLZMA_API_STATIC when compiling code that
will be linked against static liblzma. Having it there on
systems other than Windows does no harm.

See: https://www.msys2.org/docs/pkgconfig/

21 months agoCMake: Create liblzma.def when building liblzma.dll with MinGW-w64.
Lasse Collin [Wed, 27 Sep 2023 19:46:20 +0000 (22:46 +0300)] 
CMake: Create liblzma.def when building liblzma.dll with MinGW-w64.

21 months agoCMake: Change one CMAKE_CURRENT_SOURCE_DIR to CMAKE_CURRENT_LIST_DIR.
Lasse Collin [Thu, 26 Oct 2023 18:44:42 +0000 (21:44 +0300)] 
CMake: Change one CMAKE_CURRENT_SOURCE_DIR to CMAKE_CURRENT_LIST_DIR.

In this case they have identical values.

21 months agoCMake/Windows: Fix the import library filename.
Lasse Collin [Sun, 1 Oct 2023 16:10:57 +0000 (19:10 +0300)] 
CMake/Windows: Fix the import library filename.

Both PREFIX and IMPORT_PERFIX have to be set to "" to get
liblzma.dll and liblzma.dll.a.

21 months agoBuild: Detect -fsanitize= in CFLAGS and incompatible build options.
Lasse Collin [Wed, 25 Oct 2023 16:13:25 +0000 (19:13 +0300)] 
Build: Detect -fsanitize= in CFLAGS and incompatible build options.

Now configure will fail if -fsanitize= is found in CFLAGS
and sanitizer-incompatible ifunc or Landlock sandboxing
would be used. These are incompatible with one or more sanitizers.
It's simpler to reject all -fsanitize= uses instead of trying to
pass those that might not cause problems.

CMake-based build was updated similarly. It lets the configuration
finish (SEND_ERROR instead of FATAL_ERROR) so that both error
messages can be seen at once.

21 months agoCI: Disable sandboxing in fsanitize=address,undefined job.
Jia Tan [Mon, 23 Oct 2023 16:50:08 +0000 (00:50 +0800)] 
CI: Disable sandboxing in fsanitize=address,undefined job.

The sandboxing on Linux now supports Landlock, which restricts all
supported filesystem actions after xz opens the files it needs. The
sandbox is only enabled when one file is input and we are writing to
standard out. With fsanitize=address,undefined, the instrumentation
needs to read additional files after the sandbox is in place. This
forces all xz based test to fail, so the sandbox must instead be
disabled.

21 months agoCI: Allow disabling the sandbox in ci_build.sh.
Jia Tan [Mon, 23 Oct 2023 16:15:39 +0000 (00:15 +0800)] 
CI: Allow disabling the sandbox in ci_build.sh.

21 months agoCMake: Don't shadow the cache entry ENABLE_THREADS with a normal variable.
Lasse Collin [Wed, 11 Oct 2023 16:47:44 +0000 (19:47 +0300)] 
CMake: Don't shadow the cache entry ENABLE_THREADS with a normal variable.

Using set(ENABLE_THREADS "posix") is confusing because it sets
a new normal variable and leaves the cache entry with the same
name unchanged. The intent wasn't to change the cache entry so
this switches to a different variable name.

21 months agoDocs: Update INSTALL about sandboxing support.
Lasse Collin [Mon, 9 Oct 2023 19:28:49 +0000 (22:28 +0300)] 
Docs: Update INSTALL about sandboxing support.

21 months agoxz: Support basic sandboxing with Linux Landlock (ABI versions 1-3).
Lasse Collin [Mon, 9 Oct 2023 19:07:52 +0000 (22:07 +0300)] 
xz: Support basic sandboxing with Linux Landlock (ABI versions 1-3).

It is enabled only when decompressing one file to stdout,
similar to how Capsicum is used.

Landlock was added in Linux 5.13.

21 months agoCMake: Edit threading related messages.
Lasse Collin [Mon, 9 Oct 2023 18:12:31 +0000 (21:12 +0300)] 
CMake: Edit threading related messages.

It's mostly to change from "thread method" to "threading method".

21 months agoCMake: Use FATAL_ERROR if user-supplied options aren't understood.
Lasse Collin [Mon, 9 Oct 2023 17:59:24 +0000 (20:59 +0300)] 
CMake: Use FATAL_ERROR if user-supplied options aren't understood.

This way typos are caught quickly and compounding error messages
are avoided (a single typo could cause more than one error).

This keeps using SEND_ERROR when the system is lacking a feature
(like threading library or sandboxing method). This way the whole
configuration log will be generated in case someone wishes to
report a problem upstream.

21 months agoCMake: Add sandboxing support.
Lasse Collin [Mon, 9 Oct 2023 15:37:32 +0000 (18:37 +0300)] 
CMake: Add sandboxing support.

21 months agoSimplify detection of Capsicum support.
Lasse Collin [Mon, 9 Oct 2023 15:13:08 +0000 (18:13 +0300)] 
Simplify detection of Capsicum support.

This removes support for FreeBSD 10.0 and 10.1 which used
<sys/capability.h> instead of <sys/capsicum.h>. Support for
FreeBSD 10.1 ended on 2016-12-31. So now FreeBSD >= 10.2 is
required to enable Capsicum support.

This also removes support for Capsicum on Linux (libcaprights)
which seems to have been unmaintained since 2017 and Linux 4.11:
https://github.com/google/capsicum-linux