Commit Graph

337 Commits

Author SHA1 Message Date
Yann Collet
52646e8d75 first proposal for LZ4_USER_MEMORY_FUNCTIONS
makes it possible to replace at link time
malloc, calloc and free
by user-provided functions
which must be named LZ4_malloc(), LZ4_calloc() and LZ4_free().

answer #937
2020-11-08 21:17:32 -08:00
Yann Collet
e251a84025 fix minor UBs
- check alignment before casting a pointer
- saveDict : don't memmove() on NULL dst
2020-11-07 19:42:57 -08:00
Yann Collet
1d02141bf8
Merge pull request #941 from lz4/revertinline
Revert "Replace "static" to "LZ4_FORCE_INLINE" for small functions"
2020-11-07 17:18:04 -08:00
Yann Collet
f61eeb7793 Revert "Replace "static" to "LZ4_FORCE_INLINE" for small functions"
This reverts commit 0e3933edd4.
2020-11-07 11:02:30 -08:00
Yann Collet
d4bfcf8489 fix #935
minor: identical declaration and prototypes of `LZ4HC_compress_optimal()`

also :
very minor optimization of `LZ4_memcpy_using_offset()`
2020-11-07 10:06:52 -08:00
Yann Collet
b5e2a4acd9
Merge pull request #936 from lz4/alignTest
More alignment tests
2020-11-06 20:27:42 -08:00
Yann Collet
211d653ff8 re-enable alignment test on all targets 2020-11-06 16:43:14 -08:00
Yann Collet
e968a24129 unified alignment test
across lz4.c and lz4hc.c
2020-11-06 14:46:48 -08:00
remittor
0e3933edd4 Replace "static" to "LZ4_FORCE_INLINE" for small functions
The "static" specifier does not guarantee that the function will be inlined.
2020-10-07 09:52:40 +03:00
remittor
749bd91a06 Replace define LZ4_FORCE_O2_INLINE_GCC_PPC64LE to LZ4_FORCE_INLINE
There is no reason to separate these two definitions!
2020-10-07 09:51:08 +03:00
remittor
c4792cdfa9 Fix: The "inline" specifier do not use for LZ4_wildCopy8 and LZ4_wildCopy32
This problem was reproduced on MSVC 2015 (32-bit). Both functions were called using the operator "call".
2020-10-06 17:16:43 +03:00
Yann Collet
7d21f761c3 fix conversion warning 2020-09-29 21:53:42 -07:00
Yann Collet
ad2d2764c7 fix minor static analyzer warnings
detected by scan-build, cppcheck and advanved compilation flags
fix #786
2020-09-29 17:20:52 -07:00
Yann Collet
78f4fdbb89
Merge pull request #923 from lz4/fix784
fix efficiency of LZ4_compress_HC_destSize()
2020-09-28 14:04:56 -07:00
Yann Collet
ab89dda91d improved last literals run on LZ4_compress_destSize
applying new more accurate formula from LZ4_compress_HC_destSize()

also : fix some minor display issue in tests/frametest
2020-09-28 11:39:00 -07:00
Yann Collet
89736e4e27 ensure last match not too close to end
must respect MFLIMIT distance from oend
2020-09-27 23:59:56 -07:00
Yann Collet
8a362a8ac8
Merge pull request #921 from lz4/doubleNull
fix compressing into NULL
2020-09-27 21:09:06 -07:00
Yann Collet
e7fe105ac6 fix efficiency of LZ4_compress_HC_destSize()
LZ4_compress_HC_destSize() had a tendency
to discard its last match when this match overflowed specified dstBuffer limit.
The impact is generally moderate,
but occasionally huge,
typically when this last match is very large
(such as compressing a bunch of zeroes).

Issue #784 fixed for both Chain and Opt implementations.

Added a unit test suggested by @remittor checking this topic.
2020-09-27 21:04:40 -07:00
Anton Kochkov
9730d91110 Fix compilation with TinyCC 2020-09-27 17:07:51 +08:00
Yann Collet
ee4f37d284 fix compressing into NULL
fails properly
bug discovered by oss-fuzz
2020-09-26 11:31:57 -07:00
Yann Collet
10d2e1c694 fixed lz4frame with blocks of size 1
properly track history
2020-09-17 14:43:02 -07:00
Yann Collet
ee01df1271 added the actual code change 2020-09-16 23:46:39 -07:00
Yann Collet
c5d6f8a8be fix #783
LZ4_decompress_safe_partial()
now also supports a scenario where
nb_bytes_to_generate is <= block_decompressed_size
And
nb_bytes_to_read is >= block_compressed_size.

Previously, the only supported scenario was
nb_bytes_to_read == block_compress_size.

Pay attention that,
if nb_bytes_to_read is > block_compressed_size,
then, necessarily, it requires that
nb_bytes_to_generate is <= block_decompress_size.
If both are larger, it will generate corrupted data.
2020-08-27 00:17:57 -07:00
Yann Collet
3e3a006c6f Merge branch 'dev' into extraInput 2020-08-26 23:20:28 -07:00
Yann Collet
5243173b23 added documentation about LZ4_FORCE_SW_BITCOUNT
Also : added memory-frugal software byte count for big endian 64-bit cpus.
Disabled by default.
2020-08-25 22:17:29 -07:00
Yann Collet
ee0a3cfa0c
Merge pull request #898 from aqrit/aqrit-prefixlen
rejigger bit counting intrinsics
2020-08-24 15:13:18 -07:00
Yann Collet
0002563be8 removed LZ4_compress_fast_force()
which serves no more purpose.

The comment implies that the simple presence of this unused function was affecting performance,
and that's the reason why it was not removed earlier.
This is likely another side effect of instruction alignment.

It's obviously unreliable to rely on it in this way,
meaning that the impact will be different, positive of negative,
with any minor code change, and any minor compiler version change, even parameter change.
2020-08-21 19:23:49 -07:00
aqrit
e45defa8bd
silence warning
MSVC debug mode complains
2020-08-17 17:53:07 -04:00
BellaXlp
ab713923a2
fix issue #783 (#862)
* fix issue #783
2020-08-12 14:42:10 -07:00
aqrit
e72897402d
rejigger bit counting intrinsics
Fix lz4/lz4#867
Optimize software fallback routines.
Delete some faulty (and dead?) MSVC big endian code.
2020-08-11 21:14:09 -04:00
Yann Collet
b26c140a54
Merge pull request #895 from lz4/hugefast
Fix #876
2020-08-10 12:52:32 -07:00
Yann Collet
7b1b078dfc fix #876
by introducing a max limit acceleration value
2020-08-10 11:03:27 -07:00
W. Felix Handte
a78235e6ad Fix Enum Casts
Fixes `-Wsign-compare` issues.
2020-08-10 13:47:08 -04:00
W. Felix Handte
9af86f0841 Remove dirty Field From LZ4_stream_t 2020-08-06 16:06:40 -04:00
W. Felix Handte
d7399232a4 Remove Extraneous Reset in LZ4_attach_dictionary()
Nothing internally sets dirty anymore. The only way to get that is if you use
an uninitialized context, in which case your warranty is void anyways.
2020-08-05 12:46:32 -04:00
Nick Terrell
fe2a1b3707 Call LZ4_memcpy() instead of memcpy()
`LZ4_memcpy()` uses `__builtin_memcpy()` to ensure that clang/gcc
can inline the `memcpy()` calls in freestanding mode.

This is necessary for decompressing the Linux Kernel with LZ4.
Without an analogous patch decompression ran at 77 MB/s, and with
the patch it ran at 884 MB/s.
2020-08-03 11:28:02 -07:00
Yann Collet
f4054274fa
Merge pull request #860 from adeason/old-style-definitions
Avoid old-style function definitions
2020-07-28 17:44:25 -07:00
Yann Collet
48f9ecfb34
Merge pull request #863 from Devernua/reducing_stack_usage_in_t_alignment
Reducing stack usage in _t_alignment checks
2020-07-16 09:44:40 -07:00
Alexander Gallego
e68c7d3878 avoid computing 0 offsets from null pointers
Similar work in the kernel:
https://patchwork.kernel.org/patch/11351499/

UBsan (+clang-10) complains about doing pointer arithmetic (adding 0)
to a nullpointer.

This patch is tested with clang-10+ubsan
2020-07-08 08:30:07 -07:00
Aleksandr Kukuev
7a75b045bd Reducing stack usage in _t_alignment checks 2020-05-11 23:32:02 +03:00
Andrew Deason
12001d6c1a Avoid old-style function definitions
Define 0-argument functions like foo(void) instead of foo(), in order
to avoid a warning with -Wold-style-definition. This makes it easier
to embed lz4.c in projects that compile with -Werror
-Wold-style-definition.
2020-05-07 15:02:09 -05:00
Bartosz Taudul
7224f9bd5d Force inline small functions used by LZ4_compress_generic. 2020-01-17 00:37:47 +01:00
Yann Collet
d755f87f9f fixed lz4hc assert error
when src ptr is in very low memory area (< 64K),
the virtual reference to data in dictionary
might end up in a very high memory address.

Since it's not a "real" memory address,
just a virtual one, to calculate distance,
it doesn't matter : only distance matters.

The assert was to restrictive.
Fixed.
2019-12-03 14:49:22 -08:00
Yann Collet
0f6cbd996f faster decoding speed with Visual
by enabling the fast decoder path.
Visual requires a different set of macro constants to detect x86 / x64.

On my laptop, decoding speed on x64 went up from 3.12 to 3.45 GB/s.
32-bit is less impressive, though still favorable,
with speed increasing from 2.55 to 2.60 GB/s.

So both cases are now enabled.

Suggested by Bartosz Taudul (@wolfpld).
2019-12-02 16:38:33 -08:00
Nigel Tao
c5a83c1a48 Have read_variable_length use fixed size types
Otherwise, the output from decoding LZ4-compressed input could be
platform dependent.

Also add a compile-time check to confirm the existing code's assumptions
that, if <stdint.h> isn't used, then sizeof(int) == 4.

Updates #792
2019-09-21 12:38:46 +10:00
Nick Terrell
d7cad81093 [LZ4_compress_destSize] Fix off-by-one error
PR#756 fixed the data corruption bug, but didn't clear `ip`. PR#760
fixed that off-by-one error, but missed the case where `ip == filledIp`,
which is harder for the fuzzers to find (it took 20 days not 1 day).

Verified this fixed the issue reported by OSS-Fuzz.

Credit to OSS-Fuzz.
2019-08-09 10:36:46 -07:00
W. Felix Handte
4c58006719 Only Bump Offset When Attaching Non-Null Dictionary
We do want to bump, even if the dictionary is empty, but we **don't** want to
bump if the dictionary is null.
2019-08-06 19:08:41 -04:00
W. Felix Handte
4f49d744e8 Add Attach Dict Debug Log 2019-08-06 18:54:03 -04:00
W. Felix Handte
918269a4e3 Make Attaching an Empty Dict Behave the Same as Using it Directly
When using an empty dictionary, we bail out of loading or attaching it in
ways that leave the working context in potentially slightly different states.
In particular, in some paths, we will cause the currentOffset to be non-zero,
while in others we would allow it to remain 0.

This difference in behavior is perfectly harmless, but in some situations, it
can produce slight differences in the compressed output. For sanity's sake,
we currently try to maintain a strict correspondence between the behavior of
the dict attachment and the dict loading paths. This patch restores them to
behaving identically.

This shouldn't have any negative side-effects, as far as I can tell. When
writing the dict attachment code, I tried to preserve zeroed currentOffsets
when possible, since they benchmarked as very slightly faster. However, the
case of attaching an empty dictionary is probably rare enought that it's
acceptable to minisculely degrade performance in that corner case.
2019-08-06 18:50:33 -04:00
Yann Collet
e18fbd51c1 silence msan warning when offset==0 2019-08-06 15:35:49 +02:00