Commit Graph

229 Commits

Author SHA1 Message Date
Takayuki Matsuoka
50915609a9 Fix: Disable LZ4HC correspond functions when LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION is enabled 2022-08-07 19:07:41 +09:00
Yann Collet
ca26930a91
Merge pull request #1124 from t-mat/compile-time-purge-memalloc-func
Introduce LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION
2022-08-05 21:36:57 +02:00
Takayuki Matsuoka
fa889cf6da Introduce LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION
This changeset introduces new compile time switch macro LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION
which removes the following functions when it's defined.

```
// lz4.c
LZ4_createStream
LZ4_freeStream
LZ4_createStreamDecode
LZ4_freeStreamDecode
LZ4_create              // legacy

// lz4hc.c
LZ4_createStreamHC(void)
LZ4_freeStreamHC
LZ4_createHC            // legacy
LZ4_freeHC              // legacy
```

These functions uses dynamic memory allocation functions such as malloc() and free().
It'll be useful for freestanding environment which doesn't have these allocation functions.

Since this change breaks API, this macro is only valid with lz4 as a static linked object.
2022-07-31 21:10:55 +09:00
Takayuki Matsuoka
5d80375ded New macro for memcpy, memmove and memset
This changeset introduces the following external macros.

- Add new macro LZ4_memset() which enables to inject external function as memset().
- Similar macro LZ4_memmove() for memmove().
- In same manner, LZ4_memcpy() also can be overriden by external macro.
2022-07-31 20:59:09 +09:00
Yann Collet
47681c72ff removed ->dictBase from lz4hc state
replaced by ->dictStart
2022-07-13 13:09:05 +02:00
Yann Collet
20d4ff5361 removed ->base from lz4hc state
replaced by ->prefixStart
2022-07-13 11:48:31 +02:00
Yann Collet
d174f975d2 clarify static sizes of states for static allocation 2022-07-12 21:28:12 +02:00
Yann Collet
4f984e45a5 added target test-compile-with-lz4-memory-usage
and run it in GA CI
2022-01-31 14:51:20 -08:00
Yann Collet
e4f5a34d16 fixed bug in optimal parser
discovered by @yoniko.
2022-01-28 16:51:28 -08:00
Dimitri Papadopoulos
4bdfb08b95
Fix typos found by codespell 2021-11-25 15:32:37 +01:00
TotalJustice
2216d45e04 fix LZ4HC_HEAPMODE macro guard 2021-06-25 15:16:22 +01:00
klebertosantos
29a6a1f494 fix null pointer dereference 2021-03-10 09:37:57 -03:00
Simon Giesecke
06b07e175e Don't trigger UBSan warning in LZ4_resetStreamHC_fast if LZ4_streamHCPtr->internal_donotuse.end is NULL. 2021-01-07 10:21:48 +01:00
Yann Collet
87a80acbe7 updated license & header dates 2020-11-25 14:45:14 -08:00
Yann Collet
f61b034cd7 fix minor win32 warning 2020-11-14 20:39:23 -08:00
Yann Collet
44b13db532 Merge branch 'dev' into customMem 2020-11-08 23:26:19 -08:00
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
2a2b10f192 fixed remaining ubsan warnings 2020-11-08 18:08:43 -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
a2222a879f fix #926
fix incorrect behavior of LZ4_saveDictHC()
when invoked right after initialization.
2020-11-07 18:12:26 -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
e968a24129 unified alignment test
across lz4.c and lz4hc.c
2020-11-06 14:46:48 -08:00
Yann Collet
664427aa8f
Merge pull request #930 from remittor-pr/fix_msvc
Fix: The "inline" specifier do not use for LZ4_wildCopy8 and LZ4_wildCopy32
2020-10-31 01:44:21 -07: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
c24e979063 [lz4hc] Made function LZ4HC_encodeSequence a human readable 2020-10-03 18:32:34 +03:00
Yann Collet
2631002f74 preserver alignment test on Visual Studio x64
this it works fine in this environment
(only x86 is suspicious)
2020-10-02 15:51:14 -07:00
Yann Collet
1e31f1d25c fix bad init scenario 2020-09-30 22:51:17 -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
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
a13c79d56d fix incorrect counting
after truncation of last sequence
2020-09-27 22:47:05 -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
Aleksandr Kukuev
7a75b045bd Reducing stack usage in _t_alignment checks 2020-05-11 23:32:02 +03: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
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
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
W. Felix Handte
40943ba0c9 Unconditionally Clear dictCtx 2019-07-18 13:35:12 -04:00
W. Felix Handte
369fb3900c Fix Data Corruption Bug when Streaming with an Attached Dict in HC Mode
This diff fixes an issue in which we failed to clear the `dictCtx` in HC
compression. The `dictCtx` is not supposed to be used when an `extDict` is
present: matches found in the `dictCtx` do not account for the presence of an
`extDict` segment, and their offsets are therefore miscalculated when one is
present. This can lead to data corruption.

This diff clears the `dictCtx` whenever setting an `extDict`.

This issue was uncovered by @terrelln's fuzzing work.
2019-07-18 12:48:41 -04:00
Hitatm
8ac954aa71 bugfix: correctly control the offset < LZ4_DISTANCE_MAX,when change the value of LZ4_DISTANCE_MAX, 2019-07-15 22:53:46 +08:00
Yann Collet
ae199124e5 fixed read-after input in LZ4_decompress_safe() 2019-04-18 18:50:51 -07:00
Yann Collet
0b876db6d4 address a few minor Visual warnings
and created target cxx17build
2019-04-18 16:07:16 -07:00
Yann Collet
6fc763cd98 ensure consistent definition and usage of FREEMEM
as suggested by @sloutsky in #671
2019-04-16 11:26:03 -07:00