Commit Graph

878 Commits

Author SHA1 Message Date
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
Yann Collet
fa5435bca9
Merge pull request #897 from lz4/lz4wlib
added target lz4-wlib
2020-08-18 10:24:36 -07:00
Yann Collet
e9cfa49d0d Clarifies and fix EndMark
EndMark, the 4-bytes value indicating the end of frame,
must be `0x00000000`.

Previously, it was just mentioned as a `0-size` block.
But such definition could encompass uncompressed blocks of size 0,
with a header of value `0x80000000`.

But the intention was to also support uncompressed empty blocks.
They could be used as a keep-alive signal.
Note that compressed empty blocks are already supported,
it's just that they have a size 1 instead of 0 (for the `0` token).

Unfortunately, the decoder implementation was also wrong,
and would also interpret a `0x80000000` block header as an endMark.

This issue evaded detection so far simply because
this situation never happens, as LZ4Frame always issues
a clean 0x00000000 value as a endMark.
It also does not flush empty blocks.

This is fixed in this PR.
The decoder can now deal with empty uncompressed blocks,
and do not confuse them with EndMark.
The specification is also clarified.
Finally, FrameTest is updated to randomly insert empty blocks during fuzzing.
2020-08-12 17:27:33 -07:00
Yann Collet
3dd34df751 added target lz4-wlib
variant of lz4 linking to liblz4 dynamic library

requires the dynamic library to expose static-only symbols (experimental API)

Example for #888
2020-08-11 14:07:51 -07:00
Yann Collet
f328e329b3 Merge branch 'fix832' into dev 2020-08-10 18:17:09 -07:00
Yann Collet
28e5a4e054 fixed test of gnu c version 2020-08-10 17:11:49 -07:00
Yann Collet
ac65f939cd
Merge pull request #896 from lz4/fix832
fix #832
2020-08-10 14:31:48 -07:00
Yann Collet
b26c140a54
Merge pull request #895 from lz4/hugefast
Fix #876
2020-08-10 12:52:32 -07:00
Yann Collet
a29ade17a0 fix #832
does no longer rely on default 0-interpretation when __GNUC__ is not defined
2020-08-10 11:51:57 -07:00
Yann Collet
ad14a98a09
Merge pull request #892 from felixhandte/lz4-clean-up-fast-reset
Remove dirty Flag in LZ4_stream_t
2020-08-10 11:28:46 -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
Yann Collet
97654d3cd2
Merge pull request #856 from indragiek/indragiek/lz4f-visibility
Add LZ4FLIB_VISIBILITY for controlling library symbol visibility
2020-08-08 13:21:07 -07:00
W. Felix Handte
9af86f0841 Remove dirty Field From LZ4_stream_t 2020-08-06 16:06:40 -04:00
Indragie Karunaratne
ae1372690d LZ4LIB_VISIBILITY -> LZ4FLIB_VISIBILITY in comment 2020-08-05 15:34:07 -06: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
Yann Collet
8ef649f3a8
Merge pull request #866 from sandyharvie/dev
Fix issue #865
2020-07-13 18:09:02 -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
Christopher Harvie
57c35511d4 fix LZ4F_compressBound when automatic flushing is enabled 2020-05-13 21:48:12 -04: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
Indragie Karunaratne
8ec5ee30be Add LZ4FLIB_VISIBILITY for controlling library symbol visibility 2020-04-26 14:51:41 -07:00
Yan Pashkovsky
4cc9d863a3 fix malloc handling 2020-02-03 16:50:02 +03:00
Yan Pashkovsky
2553cd550b fix: allocate LZ4HC_optimal_t opt on heap each time (#837) 2020-01-31 20:10:56 +03: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
b5b9760c80
Merge pull request #772 from lz4/offset0
silence msan warning when offset==0
2019-08-06 19:17:16 +02:00
Yann Collet
e18fbd51c1 silence msan warning when offset==0 2019-08-06 15:35:49 +02:00
Nick Terrell
064adb2e8d [lz4hc] Chain swap with acceleration 2019-07-31 10:17:26 -07:00
Nick Terrell
38c3945de3 [lz4hc] Only allow chain swapping forwards
When the match is very long and found quickly, we can do
matchLength * nbCompares iterations through the chain
swapping, which can really slow down compression.
2019-07-31 10:17:26 -07:00
Nick Terrell
be1738aa46 [lz4hc] Fix pattern detection end of dictionary
The pattern detection in extDict mode could put `matchIndex`
within the last 3 bytes of the dictionary. This would cause
a read out of bounds.
2019-07-31 10:17:21 -07:00
Nick Terrell
58ea585878 [lz4hc] Fix minor pessimization in extDict pattern matching
We should be comparing `matchPtr` not `ip`. This bug just means
that this branch was not taken, so we might miss some of the
forward length.
2019-07-31 10:16:25 -07:00
Nick Terrell
7e97bf377d [lz4hc] Improve pattern detection in ext dict
It is important to continue to look backwards if the current pattern
reaches `lowPrefixPtr`. If the pattern detection doesn't go all the
way to the beginning of the pattern, or the end of the pattern it
slows down the search instead of speeding it up.

The slow unit in `round_trip_stream_fuzzer` used to take 12 seconds
to run with -O3, now it takes 0.2 seconds.

Credit to OSS-Fuzz
2019-07-31 10:16:21 -07:00
Nick Terrell
4c1d4c437d [LZ4HC] Speed up pattern compression with external dictionary
Fixes #761.
2019-07-24 10:59:20 -07:00
Yann Collet
fb8a159436
Merge pull request #763 from terrelln/unused
[lz4frame] Fix unused variable warnings in fuzzing mode
2019-07-19 16:54:01 -07:00
Yann Collet
7a516411d4
Merge pull request #760 from terrelln/destSize
[LZ4_compress_destSize] Fix off-by-one error in fix
2019-07-19 15:22:51 -07:00
Nick Terrell
87e52f7d5d [lz4frame] Fix unused variable warnings in fuzzing mode 2019-07-19 14:44:06 -07:00
Nick Terrell
b487660309 [lz4frame] Skip magic and checksums in fuzzing mode
When `FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION` is defined we skip
magic and checksum checks. This makes it easier to fuzz decompression.
2019-07-18 18:45:32 -07:00
Nick Terrell
1f236e0790 Fix LZ4_attach_dictionary with empty dictionary 2019-07-18 12:29:15 -07:00
Nick Terrell
7c32101c65 [LZ4_compress_destSize] Fix off-by-one error in fix
The next match is looking at the current ip, not the next ip,
so it needs to be cleared as well.

Credit to OSS-Fuzz
2019-07-18 12:20:29 -07:00
W. Felix Handte
40943ba0c9 Unconditionally Clear dictCtx 2019-07-18 13:35:12 -04:00