]> git.ipfire.org Git - thirdparty/xz.git/log
thirdparty/xz.git
15 months agoliblzma: Set all values in lzma_lz_encoder to NULL after allocation.
Lasse Collin [Tue, 7 May 2024 16:56:46 +0000 (19:56 +0300)] 
liblzma: Set all values in lzma_lz_encoder to NULL after allocation.

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.

(based on commit 8191720eac950a5db89c4d33d6beea6316a49b19)

15 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.

(cherry picked from commit 27ab54af848ec4adc9c17362f6c64a42a7003df5)

15 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.

(cherry picked from commit 019afd72e02339a6bf00c32bfb56f649c637dd6b)

15 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.

(cherry picked from commit 6af9a4cbe5b677a2c48b009b370539ad30dc269a)

15 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.

(cherry picked from commit 7dc466d62155cb7442aa5e10633e084ed384360d)

15 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.

(cherry picked from commit 0ecfaa6df91f7c37510f370295f593b9c0b88b98)

15 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.

(cherry picked from commit 9b469da8f3415e12d650705c7a82256e62e7871b)

15 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.

(cherry picked from commit 84196e8c094402cb71b669fb9e984c56ebabb145)

15 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.

(cherry picked from commit d90ed84db9770712e2421e170076b43bda9b64a7)

15 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.

(cherry picked from commit 068ee436f4a8a706125ef43e8228b30001b1554e)

15 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.

(cherry picked from commit 6cdf0a7b7974baf58c1fd20ec3278f3b84ae56e5)

15 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.

(cherry picked from commit 33daad3961a4f07f3902b40f13e823e6e43e85da)

15 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.

(cherry picked from commit 6961a5ac7df178bfc2b7a181c40575847bc3035f)

15 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.

(cherry picked from commit 5b9e16764905d06fa8e8339ba185ddfee304e5fb)

15 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.

(cherry picked from commit 36fabdbe67c8a8fbdc3ac695a91fc443a1328cc4)

15 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/
(cherry picked from commit 4083c8e9501a48934a5fb563d2c3ce2ae143cd27)

15 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.

(cherry picked from commit da4d04e4d6e199d28b58bd2e0df4e120c52dd5d7)

15 months agoBuild: Update visibility.m4 from Gnulib
Lasse Collin [Tue, 7 May 2024 13:21:15 +0000 (16:21 +0300)] 
Build: Update visibility.m4 from Gnulib

This fixes the syntax of the "serial" line and renames
a temporary variable.

15 months agoBuild: Update visibility.m4 from Gnulib.
Jia Tan [Thu, 12 Oct 2023 12:12:18 +0000 (20:12 +0800)] 
Build: Update visibility.m4 from Gnulib.

Updating from version 6 -> 8 from upstream. Declarations for variables
and function bodies were added to avoid unnecessary failures with
-Werror.

(cherry picked from commit 4cc91ceb3992ef4f51302b56178c3b2c2aeaaaad)

15 months agoUpdate THANKS.
Lasse Collin [Fri, 6 Oct 2023 16:36:35 +0000 (19:36 +0300)] 
Update THANKS.

(cherry picked from commit 1824a6007cb1c8d5d7abcc7bf649148bc06fa72c)

15 months agoCMake: Fix Windows build with Clang/LLVM 17.
Lasse Collin [Wed, 27 Sep 2023 16:54:35 +0000 (19:54 +0300)] 
CMake: Fix Windows build with Clang/LLVM 17.

llvm-windres 17.0.0 has more accurate emulation of GNU windres, so
the hack for GNU windres must now be used with llvm-windres too.

LLVM 16.0.6 has the old behavior and there likely won't be more
16.x releases. So we can simply check for >= 17.0.0.

The workaround must not be used with Clang that is acting in
MSVC mode. This checks for the known environments that need
the workaround instead of using "NOT MSVC".

See also:
https://github.com/llvm/llvm-project/commit/2bcc0fdc58a220cb9921b47ec8a32c85f2511a47

(cherry picked from commit 38171492ded6426ddf53d0c200fa8c93fcd02a60)

15 months agoBuild: Fix underquoted AC_LANG_SOURCE.
Lasse Collin [Tue, 26 Sep 2023 10:51:31 +0000 (13:51 +0300)] 
Build: Fix underquoted AC_LANG_SOURCE.

It made no practical difference in this case.

(cherry picked from commit f3c32762ae309afa2fe330e7fb397acfdedc4d37)

15 months agosysdefs.h: Update the comment about __USE_MINGW_ANSI_STDIO.
Lasse Collin [Sun, 24 Sep 2023 13:32:32 +0000 (16:32 +0300)] 
sysdefs.h: Update the comment about __USE_MINGW_ANSI_STDIO.

(cherry picked from commit 4ae13cfe0dedb8ddc3cf9ded8cd1ac09361b3bd1)

15 months agoxz: Windows: Don't (de)compress to special files like "con" or "nul".
Lasse Collin [Thu, 21 Sep 2023 23:33:29 +0000 (02:33 +0300)] 
xz: Windows: Don't (de)compress to special files like "con" or "nul".

Before this commit, the following writes "foo" to the
console and deletes the input file:

    echo foo | xz > con_xz
    xz --suffix=_xz --decompress con_xz

It cannot happen without --suffix because names like con.xz
are also special and so attempting to decompress con.xz
(or compress con to con.xz) will already fail when opening
the input file.

Similar thing is possible when compressing. The following
writes to "nul" and the input file "n" is deleted.

    echo foo | xz > n
    xz --suffix=ul n

Now xz checks if the destination is a special file before
continuing. DOS/DJGPP version had a check for this but
Windows (and OS/2) didn't.

(cherry picked from commit 660c8c29e57d30dbd5009ef1f0ec1bbe195ccef6)

15 months agoCMake: Bump maximum policy version to 3.27.
Lasse Collin [Tue, 12 Sep 2023 18:12:34 +0000 (21:12 +0300)] 
CMake: Bump maximum policy version to 3.27.

There are several new policies. CMP0149 may affect the Windows SDK
version that CMake will choose by default. The new behavior is more
predictable, always choosing the latest SDK version by default.

The other new policies shouldn't affect this package.

(cherry picked from commit 5be6275f19784cdd5a954f0188045c8ff4934d54)

15 months agoliblzma: Move a few __attribute__ uses in function declarations.
Lasse Collin [Mon, 11 Sep 2023 15:47:26 +0000 (18:47 +0300)] 
liblzma: Move a few __attribute__ uses in function declarations.

The API headers have many attributes but these were left
as is for now.

(cherry picked from commit e3478ae4f36cd06522a2fef023860893f068434d)

15 months agoxz, xzdec, lzmainfo: Use tuklib_attr_noreturn.
Lasse Collin [Mon, 11 Sep 2023 16:03:35 +0000 (19:03 +0300)] 
xz, xzdec, lzmainfo: Use tuklib_attr_noreturn.

For compatibility with C23's [[noreturn]], tuklib_attr_noreturn
must be at the beginning of declaration (before "extern" or
"static", and even before any GNU C's __attribute__).

This commit also moves all other function attributes to
the beginning of function declarations. "extern" is kept
at the beginning of a line so the attributes are listed on
separate lines before "extern" or "static".

(cherry picked from commit b71b8922ef3971e5ccffd1e213888d44abe21d11)

15 months agoRemove incorrect uses of __attribute__((__malloc__)).
Lasse Collin [Mon, 11 Sep 2023 15:53:31 +0000 (18:53 +0300)] 
Remove incorrect uses of __attribute__((__malloc__)).

xrealloc() is obviously incorrect, modern GCC docs even
mention realloc() as an example where this attribute
cannot be used.

liblzma's lzma_alloc() and lzma_alloc_zero() would be
correct uses most of the time but custom allocators
may use a memory pool or otherwise hold the pointer
so aliasing issues could happen in theory.

The xstrdup() case likely was correct but I removed it anyway.
Now there are no __malloc__ attributes left in the code.
The allocations aren't in hot paths so this should make
no practical difference.

(cherry picked from commit 359e5c6cb128dab64ea6070d21d1c240f96cea6b)

15 months agoCMake: Fix time.h checks not running on second CMake run.
Jia Tan [Tue, 12 Sep 2023 14:36:12 +0000 (22:36 +0800)] 
CMake: Fix time.h checks not running on second CMake run.

If CMake was configured more than once, HAVE_CLOCK_GETTIME and
HAVE_CLOCK_MONOTONIC would not be set as compile definitions. The check
for librt being needed to provide HAVE_CLOCK_GETTIME was also
simplified.

(cherry picked from commit a70e96d2da761b8b3a77bf14e08002d871e5950b)

15 months agoxz: Fix a too relaxed assertion and remove uses of SSIZE_MAX.
Lasse Collin [Thu, 31 Aug 2023 15:14:43 +0000 (18:14 +0300)] 
xz: Fix a too relaxed assertion and remove uses of SSIZE_MAX.

SSIZE_MAX isn't readily available on MSVC. Removing it means
that there is one thing less to worry when porting to MSVC.

(cherry picked from commit ef71f83973a20cc28a3221f85681922026ea33f5)

15 months agoUpdate THANKS.
Jia Tan [Mon, 28 Aug 2023 13:52:54 +0000 (21:52 +0800)] 
Update THANKS.

(cherry picked from commit 4b23b84b89e39a5117e16f66c3b01db4f08ed3e7)

15 months agoliblzma: Update assert in vli_ceil4().
Jia Tan [Mon, 28 Aug 2023 13:50:16 +0000 (21:50 +0800)] 
liblzma: Update assert in vli_ceil4().

The argument to vli_ceil4() should always guarantee the return value
is also a valid lzma_vli. Thus the highest three valid lzma_vli values
are invalid arguments. All uses of the function ensure this so the
assert is updated to match this.

(cherry picked from commit 773f1e8622cb1465df528cb16a749517650acd93)

15 months agoliblzma: Add overflow check for Unpadded size in lzma_index_append().
Jia Tan [Mon, 28 Aug 2023 13:31:25 +0000 (21:31 +0800)] 
liblzma: Add overflow check for Unpadded size in lzma_index_append().

This was not a security bug since there was no path to overflow
UINT64_MAX in lzma_index_append() or when it calls index_file_size().
The bug was discovered by a failing assert() in vli_ceil4() when called
from index_file_size() when unpadded_sum (the sum of the compressed size
of current Stream and the unpadded_size parameter) exceeds LZMA_VLI_MAX.

Previously, the unpadded_size parameter was checked to be not greater
than UNPADDED_SIZE_MAX, but no check was done once compressed_base was
added.

This could not have caused an integer overflow in index_file_size() when
called by lzma_index_append(). The calculation for file_size breaks down
into the sum of:

- Compressed base from all previous Streams
- 2 * LZMA_STREAM_HEADER_SIZE (size of the current Streams header and
  footer)
- stream_padding (can be set by lzma_index_stream_padding())
- Compressed base from the current Stream
- Unpadded size (parameter to lzma_index_append())

The sum of everything except for Unpadded size must be less than
LZMA_VLI_MAX. This is guarenteed by overflow checks in the functions
that can set these values including lzma_index_stream_padding(),
lzma_index_append(), and lzma_index_cat(). The maximum value for
Unpadded size is enforced by lzma_index_append() to be less than or
equal UNPADDED_SIZE_MAX. Thus, the sum cannot exceed UINT64_MAX since
LZMA_VLI_MAX is half of UINT64_MAX.

Thanks to Joona Kannisto for reporting this.

(cherry picked from commit 68bda971bb8b666a009331455fcedb4e18d837a4)

15 months agomythread.h: Fix typo error in Vista threads mythread_once().
Jamaika1 [Tue, 8 Aug 2023 12:07:59 +0000 (14:07 +0200)] 
mythread.h: Fix typo error in Vista threads mythread_once().

The "once_" variable was accidentally referred to as just "once". This
prevented building with Vista threads when
HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR was not defined.

(cherry picked from commit c0c0cd4a483a672b66a13761583bc4f84d86d501)

15 months agobuild-aux/manconv.sh: Fix US-ASCII and UTF-8 output.
Lasse Collin [Wed, 2 Aug 2023 12:19:43 +0000 (15:19 +0300)] 
build-aux/manconv.sh: Fix US-ASCII and UTF-8 output.

groff defaults to SGR escapes. Using -P-c passes -c to grotty
which restores the old behavior. Perhaps there is a better way to
get pure plain text output but this works for now.

(cherry picked from commit 6a1093c0004c42eeaef312456c295671496dd67a)

15 months agoliblzma: Prevent an empty translation unit in Windows builds.
Jia Tan [Mon, 24 Jul 2023 13:43:44 +0000 (21:43 +0800)] 
liblzma: Prevent an empty translation unit in Windows builds.

To workaround Automake lacking Windows resource compiler support, an
empty source file is compiled to overwrite the resource files for static
library builds. Translation units without an external declaration are
not allowed by the C standard and result in a warning when used with
-Wempty-translation-unit (Clang) or -pedantic (GCC).

(cherry picked from commit 19899340cf74d98304f9f5b726c72e85c7017d72)

15 months agoliblzma: Tweak #if condition in memcmplen.h.
Lasse Collin [Tue, 18 Jul 2023 10:57:54 +0000 (13:57 +0300)] 
liblzma: Tweak #if condition in memcmplen.h.

Maybe ICC always #defines _MSC_VER on Windows but now
it's very clear which code will get used.

(cherry picked from commit b406828a6dfd3caa4f77efe3ff3e3eea263eee62)

15 months agoliblzma: Omit unnecessary parenthesis in a preprocessor directive.
Lasse Collin [Tue, 18 Jul 2023 10:49:43 +0000 (13:49 +0300)] 
liblzma: Omit unnecessary parenthesis in a preprocessor directive.

(cherry picked from commit ef4a07ad9434f81417395f6fe0bb331e027a703b)

15 months agoliblzma: Prevent warning for MSYS2 Windows build.
Jia Tan [Wed, 28 Jun 2023 12:22:38 +0000 (20:22 +0800)] 
liblzma: Prevent warning for MSYS2 Windows build.

In lzma_memcmplen(), the <intrin.h> header file is only included if
_MSC_VER and _M_X64 are both defined but _BitScanForward64() was
previously used if _M_X64 was defined. GCC for MSYS2 defines _M_X64 but
not _MSC_VER so _BitScanForward64() was used without including
<intrin.h>.

Now, lzma_memcmplen() will use __builtin_ctzll() for MSYS2 GCC builds as
expected.

(cherry picked from commit 64ee0caaea06654b28afaee850fb187a11bf9cb2)

15 months agoliblzma: Prevent uninitialzed warning in mt stream encoder.
Jia Tan [Wed, 28 Jun 2023 12:31:11 +0000 (20:31 +0800)] 
liblzma: Prevent uninitialzed warning in mt stream encoder.

This change only impacts the compiler warning since it was impossible
for the wait_abs struct in stream_encode_mt() to be used before it was
initialized since mythread_condtime_set() will always be called before
mythread_cond_timedwait().

Since the mythread.h code is different between the POSIX and
Windows versions, this warning was only present on Windows builds.

Thanks to Arthur S for reporting the warning and providing an initial
patch.

(cherry picked from commit 1155471651ad456c5f90aee6435931fae65682bf)

15 months agoUpdate THANKS.
Jia Tan [Tue, 6 Jun 2023 16:10:38 +0000 (00:10 +0800)] 
Update THANKS.

(cherry picked from commit 62dd1c9bf0c66679ceeebc8b99bca136ca43bcb9)

15 months agoCMake: Protects against double find_package
Benjamin Buch [Tue, 6 Jun 2023 13:32:45 +0000 (15:32 +0200)] 
CMake: Protects against double find_package

Boost iostream uses `find_package` in quiet mode and then again uses
`find_package` with required. This second call triggers a
`add_library cannot create imported target "LibLZMA::LibLZMA"
because another target with the same name already exists.`

This can simply be fixed by skipping the alias part on secondary
`find_package` runs.

(cherry picked from commit d04eb78ab3892d3678c180437dd66379efa051fd)

2 years agoBump version and soname for 5.2.12. v5.2.12
Jia Tan [Thu, 4 May 2023 11:48:19 +0000 (19:48 +0800)] 
Bump version and soname for 5.2.12.

2 years agoAdd NEWS for 5.2.12.
Jia Tan [Tue, 2 May 2023 12:39:37 +0000 (20:39 +0800)] 
Add NEWS for 5.2.12.

2 years agoTranslations: Update the Croatian translation.
Jia Tan [Thu, 4 May 2023 12:38:52 +0000 (20:38 +0800)] 
Translations: Update the Croatian translation.

2 years agotuklib_integer.h: Fix a recent copypaste error in Clang detection.
Lasse Collin [Wed, 3 May 2023 19:46:42 +0000 (22:46 +0300)] 
tuklib_integer.h: Fix a recent copypaste error in Clang detection.

Wrong line was changed in 7062348bf35c1e4cbfee00ad9fffb4a21aa6eff7.
Also, this has >= instead of == since ints larger than 32 bits would
work too even if not relevant in practice.

2 years agoUpdate THANKS.
Jia Tan [Thu, 20 Apr 2023 12:15:00 +0000 (20:15 +0800)] 
Update THANKS.

2 years agoWindows: Include <intrin.h> when needed.
Jia Tan [Wed, 19 Apr 2023 14:22:16 +0000 (22:22 +0800)] 
Windows: Include <intrin.h> when needed.

Legacy Windows did not need to #include <intrin.h> to use the MSVC
intrinsics. Newer versions likely just issue a warning, but the MSVC
documentation says to include the header file for the intrinsics we use.

GCC and Clang can "pretend" to be MSVC on Windows, so extra checks are
needed in tuklib_integer.h to only include <intrin.h> when it will is
actually needed.

2 years agotuklib_integer: Use __builtin_clz() with Clang.
Jia Tan [Wed, 19 Apr 2023 13:59:03 +0000 (21:59 +0800)] 
tuklib_integer: Use __builtin_clz() with Clang.

Clang has support for __builtin_clz(), but previously Clang would
fallback to either the MSVC intrinsic or the regular C code. This was
discovered due to a bug where a new version of Clang required the
<intrin.h> header file in order to use the MSVC intrinsics.

Thanks to Anton Kochkov for notifying us about the bug.

2 years agoliblzma: Update project maintainers in lzma.h.
Lasse Collin [Fri, 14 Apr 2023 15:42:33 +0000 (18:42 +0300)] 
liblzma: Update project maintainers in lzma.h.

AUTHORS was updated earlier, lzma.h was simply forgotten.

2 years agoliblzma: Cleans up old commented out code.
Jia Tan [Thu, 13 Apr 2023 12:45:19 +0000 (20:45 +0800)] 
liblzma: Cleans up old commented out code.

2 years agoBuild: Removes redundant check for LZMA1 filter support.
Jia Tan [Wed, 22 Mar 2023 07:42:04 +0000 (15:42 +0800)] 
Build: Removes redundant check for LZMA1 filter support.

2 years agoBuild: Add a comment that AC_PROG_CC_C99 is needed for Autoconf 2.69.
Lasse Collin [Tue, 21 Mar 2023 12:07:51 +0000 (14:07 +0200)] 
Build: Add a comment that AC_PROG_CC_C99 is needed for Autoconf 2.69.

It's obsolete in Autoconf >= 2.70 and just an alias for AC_PROG_CC
but Autoconf 2.69 requires AC_PROG_CC_C99 to get a C99 compiler.

2 years agoBuild: configure.ac: Use AS_IF and AS_CASE where required.
Lasse Collin [Tue, 21 Mar 2023 12:04:37 +0000 (14:04 +0200)] 
Build: configure.ac: Use AS_IF and AS_CASE where required.

This makes no functional difference in the generated configure
(at least with the Autotools versions I have installed) but this
change might prevent future bugs like the one that was just
fixed in the commit 5a5bd7f871818029d5ccbe189f087f591258c294.

2 years agoUpdate THANKS.
Lasse Collin [Tue, 21 Mar 2023 11:12:03 +0000 (13:12 +0200)] 
Update THANKS.

2 years agoBuild: Fix --disable-threads breaking the building of shared libs.
Lasse Collin [Tue, 21 Mar 2023 11:11:49 +0000 (13:11 +0200)] 
Build: Fix --disable-threads breaking the building of shared libs.

This is broken in the releases 5.2.6 to 5.4.2. A workaround
for these releases is to pass EGREP='grep -E' as an argument
to configure in addition to --disable-threads.

The problem appeared when m4/ax_pthread.m4 was updated in
the commit 6629ed929cc7d45a11e385f357ab58ec15e7e4ad which
introduced the use of AC_EGREP_CPP. AC_EGREP_CPP calls
AC_REQUIRE([AC_PROG_EGREP]) to set the shell variable EGREP
but this was only executed if POSIX threads were enabled.
Libtool code also has AC_REQUIRE([AC_PROG_EGREP]) but Autoconf
omits it as AC_PROG_EGREP has already been required earlier.
Thus, if not using POSIX threads, the shell variable EGREP
would be undefined in the Libtool code in configure.

ax_pthread.m4 is fine. The bug was in configure.ac which called
AX_PTHREAD conditionally in an incorrect way. Using AS_CASE
ensures that all AC_REQUIREs get always run.

Thanks to Frank Busse for reporting the bug.
Fixes: https://github.com/tukaani-project/xz/issues/45
2 years agoBump version and soname for 5.2.11. v5.2.11
Jia Tan [Sat, 18 Mar 2023 14:25:59 +0000 (22:25 +0800)] 
Bump version and soname for 5.2.11.

2 years agoAdd NEWS for 5.2.11.
Jia Tan [Sat, 18 Mar 2023 14:16:09 +0000 (22:16 +0800)] 
Add NEWS for 5.2.11.

2 years agoUpdate the copy of GNU GPLv3 from gnu.org to COPYING.GPLv3.
Lasse Collin [Sat, 18 Mar 2023 14:00:54 +0000 (16:00 +0200)] 
Update the copy of GNU GPLv3 from gnu.org to COPYING.GPLv3.

2 years agoChange a few HTTP URLs to HTTPS.
Lasse Collin [Sat, 18 Mar 2023 13:51:57 +0000 (15:51 +0200)] 
Change a few HTTP URLs to HTTPS.

The xz man page timestamp was intentionally left unchanged.

2 years agoCMake: Require that the C compiler supports C99 or a newer standard.
Lasse Collin [Mon, 27 Feb 2023 16:38:35 +0000 (18:38 +0200)] 
CMake: Require that the C compiler supports C99 or a newer standard.

Thanks to autoantwort for reporting the issue and suggesting
a different patch:
https://github.com/tukaani-project/xz/pull/42

2 years agoUpdate THANKS.
Lasse Collin [Thu, 23 Feb 2023 18:46:16 +0000 (20:46 +0200)] 
Update THANKS.

2 years agoliblzma: Avoid null pointer + 0 (undefined behavior in C).
Lasse Collin [Tue, 21 Feb 2023 20:57:10 +0000 (22:57 +0200)] 
liblzma: Avoid null pointer + 0 (undefined behavior in C).

In the C99 and C17 standards, section 6.5.6 paragraph 8 means that
adding 0 to a null pointer is undefined behavior. As of writing,
"clang -fsanitize=undefined" (Clang 15) diagnoses this. However,
I'm not aware of any compiler that would take advantage of this
when optimizing (Clang 15 included). It's good to avoid this anyway
since compilers might some day infer that pointer arithmetic implies
that the pointer is not NULL. That is, the following foo() would then
unconditionally return 0, even for foo(NULL, 0):

    void bar(char *a, char *b);

    int foo(char *a, size_t n)
    {
        bar(a, a + n);
        return a == NULL;
    }

In contrast to C, C++ explicitly allows null pointer + 0. So if
the above is compiled as C++ then there is no undefined behavior
in the foo(NULL, 0) call.

To me it seems that changing the C standard would be the sane
thing to do (just add one sentence) as it would ensure that a huge
amount of old code won't break in the future. Based on web searches
it seems that a large number of codebases (where null pointer + 0
occurs) are being fixed instead to be future-proof in case compilers
will some day optimize based on it (like making the above foo(NULL, 0)
return 0) which in the worst case will cause security bugs.

Some projects don't plan to change it. For example, gnulib and thus
many GNU tools currently require that null pointer + 0 is defined:

    https://lists.gnu.org/archive/html/bug-gnulib/2021-11/msg00000.html

    https://www.gnu.org/software/gnulib/manual/html_node/Other-portability-assumptions.html

In XZ Utils null pointer + 0 issue should be fixed after this
commit. This adds a few if-statements and thus branches to avoid
null pointer + 0. These check for size > 0 instead of ptr != NULL
because this way bugs where size > 0 && ptr == NULL will likely
get caught quickly. None of them are in hot spots so it shouldn't
matter for performance.

A little less readable version would be replacing

    ptr + offset

with

    offset != 0 ? ptr + offset : ptr

or creating a macro for it:

    #define my_ptr_add(ptr, offset) \
            ((offset) != 0 ? ((ptr) + (offset)) : (ptr))

Checking for offset != 0 instead of ptr != NULL allows GCC >= 8.1,
Clang >= 7, and Clang-based ICX to optimize it to the very same code
as ptr + offset. That is, it won't create a branch. So for hot code
this could be a good solution to avoid null pointer + 0. Unfortunately
other compilers like ICC 2021 or MSVC 19.33 (VS2022) will create a
branch from my_ptr_add().

Thanks to Marcin Kowalczyk for reporting the problem:
https://github.com/tukaani-project/xz/issues/36

2 years agoUpdate THANKS.
Lasse Collin [Fri, 17 Feb 2023 18:56:49 +0000 (20:56 +0200)] 
Update THANKS.

2 years agoBuild: Use only the generic symbol versioning on MicroBlaze.
Lasse Collin [Fri, 17 Feb 2023 18:48:28 +0000 (20:48 +0200)] 
Build: Use only the generic symbol versioning on MicroBlaze.

On MicroBlaze, GCC 12 is broken in sense that
__has_attribute(__symver__) returns true but it still doesn't
support the __symver__ attribute even though the platform is ELF
and symbol versioning is supported if using the traditional
__asm__(".symver ...") method. Avoiding the traditional method is
good because it breaks LTO (-flto) builds with GCC.

See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101766

For now the only extra symbols in liblzma_linux.map are the
compatibility symbols with the patch that spread from RHEL/CentOS 7.
These require the use of __symver__ attribute or __asm__(".symver ...")
in the C code. Compatibility with the patch from CentOS 7 doesn't
seem valuable on MicroBlaze so use liblzma_generic.map on MicroBlaze
instead. It doesn't require anything special in the C code and thus
no LTO issues either.

An alternative would be to detect support for __symver__
attribute in configure.ac and CMakeLists.txt and fall back
to __asm__(".symver ...") but then LTO would be silently broken
on MicroBlaze. It sounds likely that MicroBlaze is a special
case so let's treat it as a such because that is simpler. If
a similar issue exists on some other platform too then hopefully
someone will report it and this can be reconsidered.

(This doesn't do the same fix in CMakeLists.txt. Perhaps it should
but perhaps CMake build of liblzma doesn't matter much on MicroBlaze.
The problem breaks the build so it's easy to notice and can be fixed
later.)

Thanks to Vincent Fazio for reporting the problem and proposing
a patch (in the end that solution wasn't used):
https://github.com/tukaani-project/xz/pull/32

2 years agoliblzma: Fix documentation for LZMA_MEMLIMIT_ERROR.
Jia Tan [Sat, 21 Jan 2023 13:32:03 +0000 (21:32 +0800)] 
liblzma: Fix documentation for LZMA_MEMLIMIT_ERROR.

LZMA_MEMLIMIT_ERROR was missing the "<" character needed to put
documentation after a member.

2 years agotuklib_physmem: Silence warning from -Wcast-function-type on MinGW-w64.
Jia Tan [Thu, 19 Jan 2023 12:35:09 +0000 (20:35 +0800)] 
tuklib_physmem: Silence warning from -Wcast-function-type on MinGW-w64.

tuklib_physmem depends on GetProcAddress() for both MSVC and MinGW-w64
to retrieve a function address. The proper way to do this is to cast the
return value to the type of function pointer retrieved. Unfortunately,
this causes a cast-function-type warning, so the best solution is to
simply ignore the warning.

2 years agoxz: Add missing comment for coder_set_compression_settings()
Jia Tan [Mon, 16 Jan 2023 13:35:45 +0000 (21:35 +0800)] 
xz: Add missing comment for coder_set_compression_settings()

2 years agoxz: Do not set compression settings with raw format in list mode.
Jia Tan [Mon, 16 Jan 2023 12:55:10 +0000 (20:55 +0800)] 
xz: Do not set compression settings with raw format in list mode.

Calling coder_set_compression_settings() in list mode with verbose mode
on caused the filter chain and memory requirements to print. This was
unnecessary since the command results in an error and not consistent
with other formats like lzma and alone.

2 years agoxz: Use ssize_t for the to-be-ignored return value from write(fd, ptr, 1).
Lasse Collin [Thu, 12 Jan 2023 04:05:58 +0000 (06:05 +0200)] 
xz: Use ssize_t for the to-be-ignored return value from write(fd, ptr, 1).

It makes no difference here as the return value fits into an int
too and it then gets ignored but this looks better.

2 years agoliblzma: Silence warnings from clang -Wconditional-uninitialized.
Lasse Collin [Thu, 12 Jan 2023 01:19:59 +0000 (03:19 +0200)] 
liblzma: Silence warnings from clang -Wconditional-uninitialized.

This is similar to 2ce4f36f179a81d0c6e182a409f363df759d1ad0.
The actual initialization of the variables is done inside
mythread_sync() macro. Clang doesn't seem to see that
the initialization code inside the macro is always executed.

2 years agoFix warnings from clang -Wdocumentation.
Lasse Collin [Thu, 12 Jan 2023 01:11:40 +0000 (03:11 +0200)] 
Fix warnings from clang -Wdocumentation.

2 years agoxz: Fix warning -Wformat-nonliteral on clang in message.c.
Jia Tan [Wed, 11 Jan 2023 14:46:48 +0000 (22:46 +0800)] 
xz: Fix warning -Wformat-nonliteral on clang in message.c.

clang and gcc differ in how they handle -Wformat-nonliteral. gcc will
allow a non-literal format string as long as the function takes its
format arguments as a va_list.

2 years agoCMake/Windows: Add a workaround for windres from GNU binutils.
Lasse Collin [Tue, 10 Jan 2023 06:50:26 +0000 (08:50 +0200)] 
CMake/Windows: Add a workaround for windres from GNU binutils.

This is combined from the following commits in the master branch:
443dfebced041adc88f10d824188eeef5b5821a9
6b117d3b1fe91eb26d533ab16a2e552f84148d47
5e34774c31d1b7509b5cb77a3be9973adec59ea0

Thanks to Iouri Kharon for the bug report, the original patch,
and testing.

2 years agoCMake: Update cmake_minimum_required from 3.13...3.16 to 3.13...3.25.
Lasse Collin [Sat, 7 Jan 2023 19:57:11 +0000 (21:57 +0200)] 
CMake: Update cmake_minimum_required from 3.13...3.16 to 3.13...3.25.

The changes listed on cmake-policies(7) for versions 3.17 to 3.25
shouldn't affect this project.

2 years agoUpdate THANKS.
Lasse Collin [Sat, 7 Jan 2023 17:50:35 +0000 (19:50 +0200)] 
Update THANKS.

2 years agoCMake: Fix a copypaste error in xzdec Windows resource file handling.
Lasse Collin [Mon, 9 Jan 2023 09:27:24 +0000 (11:27 +0200)] 
CMake: Fix a copypaste error in xzdec Windows resource file handling.

It was my mistake. Thanks to Iouri Kharon for the bug report.

2 years agoCMake/Windows: Add resource files to xz.exe and xzdec.exe.
Lasse Collin [Sat, 7 Jan 2023 17:50:03 +0000 (19:50 +0200)] 
CMake/Windows: Add resource files to xz.exe and xzdec.exe.

The command line tools cannot be built with MSVC for now but
they can be built with MinGW-w64.

Thanks to Iouri Kharon for the bug report and the original patch.

2 years agoliblzma: Update documentation for lzma_filter_encoder.
Jia Tan [Thu, 22 Dec 2022 15:14:53 +0000 (23:14 +0800)] 
liblzma: Update documentation for lzma_filter_encoder.

2 years agoDoxygen: Update .gitignore for generating docs for in source build.
Jia Cheong Tan [Tue, 20 Dec 2022 14:05:21 +0000 (22:05 +0800)] 
Doxygen: Update .gitignore for generating docs for in source build.

In source builds are not recommended, but we should still ignore
the generated artifacts.

2 years agoCMake: Update .gitignore for CMake artifacts from in source build.
Jia Tan [Fri, 16 Dec 2022 12:58:55 +0000 (20:58 +0800)] 
CMake: Update .gitignore for CMake artifacts from in source build.

In source builds are not recommended, but we can make it easier
by ignoring the generated artifacts from CMake.

2 years agoBump version and soname for 5.2.10. v5.2.10
Lasse Collin [Tue, 13 Dec 2022 11:03:20 +0000 (13:03 +0200)] 
Bump version and soname for 5.2.10.

2 years agoAdd NEWS for 5.2.10.
Lasse Collin [Tue, 13 Dec 2022 11:02:15 +0000 (13:02 +0200)] 
Add NEWS for 5.2.10.

2 years agoTests: Fix a typo in tests/files/README.
Lasse Collin [Tue, 13 Dec 2022 10:30:45 +0000 (12:30 +0200)] 
Tests: Fix a typo in tests/files/README.

2 years agoUpdate AUTHORS.
Lasse Collin [Mon, 12 Dec 2022 17:09:20 +0000 (19:09 +0200)] 
Update AUTHORS.

2 years agoxz: Make args_info.files_name a const pointer.
Lasse Collin [Thu, 8 Dec 2022 17:24:22 +0000 (19:24 +0200)] 
xz: Make args_info.files_name a const pointer.

2 years agoxz: Don't modify argv[].
Lasse Collin [Thu, 8 Dec 2022 17:18:16 +0000 (19:18 +0200)] 
xz: Don't modify argv[].

The code that parses --memlimit options and --block-list modified
the argv[] when parsing the option string from optarg. This was
visible in "ps auxf" and such and could be confusing. I didn't
understand it back in the day when I wrote that code. Now a copy
is allocated when modifiable strings are needed.

2 years agoliblzma: Check for unexpected NULL pointers in block_header_decode().
Lasse Collin [Thu, 8 Dec 2022 15:30:09 +0000 (17:30 +0200)] 
liblzma: Check for unexpected NULL pointers in block_header_decode().

The API docs gave an impression that such checks are done
but they actually weren't done. In practice it made little
difference since the calling code has a bug if these are NULL.

Thanks to Jia Tan for the original patch that checked for
block->filters == NULL.

2 years agoliblzma: Use __has_attribute(__symver__) to fix Clang detection.
Lasse Collin [Thu, 1 Dec 2022 18:04:17 +0000 (20:04 +0200)] 
liblzma: Use __has_attribute(__symver__) to fix Clang detection.

If someone sets up Clang to define __GNUC__ to 10 or greater
then symvers broke. __has_attribute is supported by such GCC
and Clang versions that don't support __symver__ so this should
be much better and simpler way to detect if __symver__ is
actually supported.

Thanks to Tomasz Gajc for the bug report.

2 years agoUpdate THANKS (sync all from master).
Lasse Collin [Mon, 12 Dec 2022 13:45:04 +0000 (15:45 +0200)] 
Update THANKS (sync all from master).

2 years agoBump version and soname for 5.2.9. v5.2.9
Lasse Collin [Wed, 30 Nov 2022 16:33:05 +0000 (18:33 +0200)] 
Bump version and soname for 5.2.9.

2 years agoAdd NEWS for 5.2.9.
Lasse Collin [Wed, 30 Nov 2022 16:31:16 +0000 (18:31 +0200)] 
Add NEWS for 5.2.9.

2 years agoChange the bug report address.
Lasse Collin [Wed, 30 Nov 2022 16:08:34 +0000 (18:08 +0200)] 
Change the bug report address.

It forwards to me and Jia Tan.

Also update the IRC reference in README as #tukaani was moved
to Libera Chat long ago.

2 years agoUpdate to HTTPS URLs in AUTHORS.
Lasse Collin [Wed, 30 Nov 2022 15:38:32 +0000 (17:38 +0200)] 
Update to HTTPS URLs in AUTHORS.

2 years agoliblzma: Remove two FIXME comments.
Lasse Collin [Sat, 26 Nov 2022 23:03:16 +0000 (01:03 +0200)] 
liblzma: Remove two FIXME comments.

2 years agoBuild: Don't put GNU/Linux-specific symbol versions into static liblzma.
Lasse Collin [Thu, 24 Nov 2022 12:52:44 +0000 (14:52 +0200)] 
Build: Don't put GNU/Linux-specific symbol versions into static liblzma.

It not only makes no sense to put symbol versions into a static library
but it can also cause breakage.

By default Libtool #defines PIC if building a shared library and
doesn't define it for static libraries. This is documented in the
Libtool manual. It can be overriden using --with-pic or --without-pic.
configure.ac detects if --with-pic or --without-pic is used and then
gives an error if neither --disable-shared nor --disable-static was
used at the same time. Thus, in normal situations it works to build
both shared and static library at the same time on GNU/Linux,
only --with-pic or --without-pic requires that only one type of
library is built.

Thanks to John Paul Adrian Glaubitz from Debian for reporting
the problem that occurred on ia64:
https://www.mail-archive.com/xz-devel@tukaani.org/msg00610.html

2 years agoCMake: Don't use symbol versioning with static library.
Lasse Collin [Wed, 23 Nov 2022 22:02:31 +0000 (00:02 +0200)] 
CMake: Don't use symbol versioning with static library.

2 years agoliblzma: Fix another invalid free() after memory allocation failure.
Lasse Collin [Wed, 23 Nov 2022 23:26:37 +0000 (01:26 +0200)] 
liblzma: Fix another invalid free() after memory allocation failure.

This time it can happen when lzma_stream_encoder_mt() is used
to reinitialize an existing multi-threaded Stream encoder
and one of 1-4 tiny allocations in lzma_filters_copy() fail.

It's very similar to the previous bug
10430fbf3820dafd4eafd38ec8be161a6978ed2b, happening with
an array of lzma_filter structures whose old options are freed
but the replacement never arrives due to a memory allocation
failure in lzma_filters_copy().

2 years agoliblzma: Add support for LZMA_SYNC_FLUSH in the Block encoder.
Jia Tan [Thu, 5 May 2022 12:53:42 +0000 (20:53 +0800)] 
liblzma: Add support for LZMA_SYNC_FLUSH in the Block encoder.

The documentation mentions that lzma_block_encoder() supports
LZMA_SYNC_FLUSH but it was never added to supported_actions[]
in the internal structure. Because of this, LZMA_SYNC_FLUSH could
not be used with the Block encoder unless it was the next coder
after something like stream_encoder() or stream_encoder_mt().

2 years agoliblzma: Add lzma_attr_warn_unused_result to lzma_filters_copy().
Lasse Collin [Wed, 23 Nov 2022 19:55:22 +0000 (21:55 +0200)] 
liblzma: Add lzma_attr_warn_unused_result to lzma_filters_copy().