aboutsummaryrefslogtreecommitdiff
path: root/linux/lib
AgeCommit message (Collapse)Author
2021-09-19Fix spelling in comments.Lasse Collin
non-splitted -> non-split uncompressible -> incompressible
2021-09-19Fix typos in comments.Lasse Collin
I happened to find these from the Linux source tree.
2021-09-19Add MicroLZMA decoder.Lasse Collin
MicroLZMA is a yet another header format variant where the first byte of a raw LZMA stream (without the end of stream marker) has been replaced with a bitwise-negation of the lc/lp/pb properties byte. MicroLZMA was created to be used in EROFS but can be used by other things too where wasting minimal amount of space for headers is important. This is implemented using most of the LZMA2 code as is so the amount of new code is small. The API has a few extra features compared to the XZ decoder. On the other hand, the API lacks XZ_BUF_ERROR support which is important to take into account when using this API. MicroLZMA doesn't support BCJ filters. In theory they could be added later as there are many unused/reserved values for the first byte of the compressed stream but in practice it is somewhat unlikely to happen due to a few implementation reasons. Thanks to Gao Xiang (EROFS developer) for testing and feedback.
2021-07-02Validate the value before, not after, assigning it to an enum variable.Lasse Collin
This might matter, for example, if the underlying type of enum xz_check was a signed char. In such a case the validation wouldn't catch an unsupported header. With most compilers it already worked correctly but it's better to change it for portability and conformance. This may increase the code size by a few bytes though. An alternative would be to use an unsigned int instead of enum xz_check but using an enumeration looks cleaner.
2021-06-20Move s->lzma.len = 0 initialization to lzma_reset().Lasse Collin
It's a more logical place even if the resetting needs to be done only once per LZMA2 stream (if lzma_reset() called in the middle of an LZMA2 stream, .len will already be 0).
2021-06-20Fix a typo in a comment.Lasse Collin
2021-05-06Add xz_dec_catrun() to support concatenated .xz files.Lasse Collin
2021-02-15Make xz_crc64.c compatible with -std=gnu89 on 32-bit platforms.Lasse Collin
When "unsigned long" is 32 bits and GCC or Clang is in gnu89 mode, the 64-bit constant doesn't become "unsigned long long" like it would in C99. This is because in gnu89 mode "unsigned long long" is a GNU extension to C89 and isn't considered when selecting the type of the integer constant. The CRC64 support was added in 2013 and the code has been broken on 32-bit platforms unless one modified the Makefile to set C99 or a newer C standard. I didn't want to omit -std=gnu89 because Linux still uses it and xz_crc64.c (which isn't in Linux) was the only place that wasn't compatible with -std=gnu89. Thanks to bzt for reporting the problem.
2020-11-02Convert HTTP links to HTTPS links.Lasse Collin
Thanks to Alexander A. Klimov.
2020-02-03Avoid overlapping memcpy() with invalid input with in-place decompression.Lasse Collin
With valid files, the safety margin described in lib/decompress_unxz.c ensures that these buffers cannot overlap. But if the uncompressed size of the input is larger than the caller thought, which is possible when the input file is invalid/corrupt, the buffers can overlap. Obviously the result will then be garbage (and usually the decoder will return an error too) but no other harm will happen when such an over-run occurs. This change only affects uncompressed LZMA2 chunks and so this should have no effect on performance.
2019-10-30Fix XZ_DYN_ALLOC to avoid useless memory reallocations.Lasse Collin
s->dict.allocated was initialized to 0 but never set after a successful allocation, thus the code always thought that the dictionary buffer has to be reallocated. Thanks to Yu Sun from Cisco Systems for reporting this bug.
2017-04-07Add two more missing fall-through comments.upstream_masterLasse Collin
2017-04-06xzembed: add fallthrough annotations to fix build with GCC7Andrei Borzenkov
GCC7 is more strict than previous versions; add missing fall through annotations. Style is modeled after similar annotations in xz_dec_lzma2.c.
2014-04-07Add comments for the intentionally missing break statements.Lasse Collin
2013-05-13Fix a typo in decompress_unxz.c.Lasse Collin
This is an old fix from 2011 that I just found from the Linux source tree. The fix was made by Lucas De Marchi.
2013-05-13Update linux/lib/xz/Kconfig from Linux 3.9.Lasse Collin
This drops "if EXPERT" from BCJ filter configuration, and the default configuration enables only the BCJ filter(s) that are likely needed on the target arch: x86 BCJ filter is enabled on x86, PowerPC filter on PowerPC, and so on. Patches do this were made by Florian Fainelli, and a typo was fixed by Paul Bolle.
2013-02-27Add optional support for CRC64.Lasse Collin
2011-09-19Fix incorrect XZ_BUF_ERROR.Lasse Collin
xz_dec_run() could incorrectly return XZ_BUF_ERROR if all of the following was true: - The caller knows how many bytes of output to expect and only provides that much output space. - When the last output bytes are decoded, the caller-provided input buffer ends right before the LZMA2 end of payload marker. So LZMA2 won't provide more output anymore, but it won't know it yet and thus won't return XZ_STREAM_END yet. - A BCJ filter is in use and it hasn't left any unfiltered bytes in the temp buffer. This can happen with any BCJ filter, but in practice it's more likely with filters other than the x86 BCJ. This fixes <https://bugzilla.redhat.com/show_bug.cgi?id=735408> where Squashfs thinks that a valid file system is corrupt. Thanks to Jindrich Novy for telling me that such a bug report exists, Phillip Lougher for providing excellent debug info, and other people on #fedora-ppc. This also fixes a similar bug in single-call mode where the uncompressed size of a XZ Block using BCJ + LZMA2 was 0 bytes and caller provided no output space. Many empty .xz files don't contain any Blocks and thus don't trigger this bug. This also tweaks a closely related detail: xz_dec_bcj_run() could call xz_dec_lzma2_run() to decode into temp buffer when it was known to be useless. This was harmless although it wasted a minuscule number of CPU cycles.
2011-07-23Add missing <linux/kernel.h> include.Lasse Collin
The min_t macro is defined in <linux/kernel.h>. On x86 <linux/kernel.h> is included indirectly via <asm/unaligned.h>, thus the missing include wasn't caught on x86. Since <linux/kernel.h> always includes <asm/byteorder.h>, there's no need to include the latter explicitly. Thanks to Russel King and and Imre Kaloz.
2011-05-01s/EMBEDDED/EXPERT/ in linux/lib/xz/Kconfig.Lasse Collin
2011-03-31Fix decoding of LZMA2 streams having no uncompressed data.Lasse Collin
No .xz encoder creates files with empty LZMA2 streams, but such files would still be valid and decompressors must accept them. Note that empty .xz files are a different thing than empty LZMA2 streams. This bug didn't affect typical .xz files that had no uncompressed data.
2010-12-02Remove an empty line from xz_dec_lzma2.c.Lasse Collin
2010-12-02Fix decompress_unxz.c API.Lasse Collin
Previously only the features that were needed by the code currently in Linux were implemented. However, <linux/decompress/generic.h> requires a few other features too, so implement them for consistency with other decompressors: - Callback-to-buffer mode - Ability to use caller-given input buffer with fill() Thanks to Phillip Lougher.
2010-11-25Don't flush() with an empty buffer in unxz().Lasse Collin
Thanks to Phillip Lougher.
2010-11-25Fix decompress_unxz.c title again.Lasse Collin
2010-11-25Fix coding style for real.Lasse Collin
I clearly wasn't fully awake with the commit ac313d. Thanks to Andrew Morton.
2010-11-25Remove noinline_for_stack.Lasse Collin
It's not needed to keep the stack usage of xz_dec_bcj_run() low because the BCJ filters get inlined into bcj_apply(), and that is not inlined into xz_dec_bcj_run(). Thanks to Andrew Morton.
2010-11-25Comment and coding style fixes.Lasse Collin
Thanks to Phillip Lougher.
2010-11-25Coding style fixes.Lasse Collin
Thanks to Andrew Morton.
2010-11-25Make bcj_x86_test_msbyte() an inline function.Lasse Collin
Thanks to Andrew Morton.
2010-11-24Fix error message in decompress_unxz.c.Lasse Collin
XZ_BUF_ERROR always means that the data is corrupt because in single-call mode the output buffer size is not limited (it can overflow) because the API doesn't pass the output buffer size. XZ_BUF_ERROR cannot occur in multi-call mode because it keeps the output buffer non-full.
2010-11-24Add a comment about using uint32_t as vli_type.Lasse Collin
2010-11-24Remove /*const*/ comments from unxz().Lasse Collin
2010-11-24Check XZ_INTERNAL_CRC32 instead of XZ_PREBOOT for xz_crc32_init().Lasse Collin
In practice this makes no difference, but it's more logical this way.
2010-11-24Use malloc() and free() in decompress_unxz.c.Lasse Collin
Using these instead of kmalloc() and kfree() makes things more consistent with the existing decompressor wrappers in Linux.
2010-11-24Add workaround for unsupported free(NULL) in pre-boot code.Lasse Collin
2010-11-24Get rid of XZ_IGNORE_KCONFIG macro.Lasse Collin
It's no longer needed because initramfs decompression uses the regular xz_dec module. The definitions of memeq(), memzero(), and get_le32() macros were moved to be done after all headers have been included. Shouldn't matter in practice but looks safer just in case some of those names appear in other headers in the future.
2010-11-21Fix compile errors in decompress_unxz.c.Lasse Collin
These problems were added in the commit 4d5e69 (Get rid of XZ_FUNC).
2010-11-20Use STATIC_RW_DATA for static read/write data.Lasse Collin
This applies to xz_crc32_table. It's needed by the pre-boot code on some architectures.
2010-11-20Get rid of XZ_FUNC.Lasse Collin
In Linux 2.6.31 (or so) and earlier, the initramfs decompression had its own compiled copy of the decompression code that got thrown away after the kernel had booted. It required that all functions were marked with __init when built for initramfs decompression. Nowadays zlib and LZO have a wrapper that requires that the respective decompressor code has been been enabled (=y) in the kernel config. Only the wrapper is marked with __init. This patch helps doing the same with the XZ decompressor.
2010-11-19Minor comment fixes.Lasse Collin
2010-11-18Bump xz_dec version to 1.0.Lasse Collin
2010-11-17Use <linux/uaccess.h> instead of <asm/uaccess.h>.Lasse Collin
Caught by checkpatch.pl.
2010-11-17Don't make memmove() static.Lasse Collin
This hack is to avoid a conflict with the memmove() prototype in the Linux headers.
2010-11-17Fix xz_dec_test.c for the newer API.Lasse Collin
2010-11-17Use (uint32_t)-1 instead of UINT32_MAX.Lasse Collin
Linux doesn't have UINT32_MAX.
2010-11-16Use XZ_DYNALLOC in decompress_unxz.c.Lasse Collin
It should be better than XZ_PREALLOC for initramfs decompression.
2010-07-02Omit explicit \0 from HEADER_MAGIC.Lasse Collin
I thought it was more readable to write it there explicitly, but since C will put a \0 there anyway, relying on that can save one byte in code size.
2010-06-09Reduce code size on x86 (32-bit and 64-bit).Lasse Collin
The variables in structures in xz_dec_lzma2.c were reordered so that the variables that the code references most are near the beginning of the structure within 128 bytes. This allows three bytes smaller instructions to access the variables, and saves around 700-900 bytes in code size.
2010-06-09Add support for allocating the LZMA2 dictionary dynamically.Lasse Collin
Previously the dictionary was preallocated at initialization time, which is useful since the decoder cannot then later run out of memory, but in several cases it is just an annoying limitation. It is now possible to enable only the needed operation mode(s) at build time, which saves a few bytes in code size if only one or two modes are actually needed. Bigger savings would be possible especially in single-call mode, but I'll think about that later. This commit changes the API by adding the mode argument to xz_dec_init(). A new return value (XZ_MEM_ERROR) was also added, but it is used only in the new XZ_DYNALLOC operation mode.