Commit Graph

890 Commits

Author SHA1 Message Date
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
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
Nick Terrell
13a2d9e34f [LZ4_compress_destSize] Fix overflow condition 2019-07-17 11:50:47 -07:00
Nick Terrell
6bc6f836a1 [LZ4_compress_destSize] Fix rare data corruption bug 2019-07-17 11:38:38 -07:00
Nick Terrell
690009e2c2 [LZ4_compress_destSize] Allow 2 more bytes of match length 2019-07-17 11:07:24 -07:00
Yann Collet
7654a5a6d2
Merge pull request #752 from terrelln/fuzzers
[ossfuzz] Improve the fuzzers
2019-07-16 11:18:09 -07:00
Nick Terrell
725cb0aafd [lz4] Fix bugs in partial decoding
* Partial decoding could read a few bytes beyond the end of the input
* Partial decoding returned an error with an empty output buffer
2019-07-15 12:21:59 -07:00
Yann Collet
6654c2cd3b ensure conformance with custom LZ4_DISTANCE_MAX
It's now possible to select a custom LZ4_DISTANCE_MAX at compile time,
provided it's <= 65535.

However, in some cases (when compressing in byU16 mode),
the new distance wasn't respected,
as it used to implied that it was necessarily within range.

Added a distance check for this case.
Also : added a new TravisCI test which ensures that
custom LZ4_DISTANCE_MAX compiles correctly
and compresses correctly (relying on `assert()` to find outsized offsets).
2019-07-15 12:11:34 -07: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
Sylvestre Ledru
12e5841e76
Remove an useless declaration 2019-07-04 18:13:36 +02:00
Yann Collet
bb5c34a875 bumped version number to v1.9.2
to reduce risks that future bug reports in `dev` branch report `v1.9.1` as the failing version.
2019-07-01 09:01:43 -07:00
Nick Terrell
e72d442300 Fix out-of-bounds read of up to 64 KB in the past 2019-06-28 14:58:35 -07:00
Yann Collet
1d759576b9 precise again that LZ4 decoder needs metadata
and that such metadata must be provided / sent / saved by the application.
2019-06-06 13:20:30 -07:00
Yann Collet
348e107d99 restored FORCE_INLINE 2019-06-04 14:04:49 -07:00
Yann Collet
280fc0856d
Merge pull request #717 from lz4/inplace
Added documentation and macro to support in-place compression and decompression
2019-05-31 12:59:38 -07:00
Yann Collet
5997e139f5 added more details for in-place documentation 2019-05-31 11:56:59 -07:00
Yann Collet
33cb8518ac decompress: changed final memcpy() into memmove()
for compatibility with in-place decompression scenarios.
2019-05-31 11:44:37 -07:00
Chenxi Mao
64b5917736 FAST_DEC_LOOP: only did offset check in specific condition.
When I did FAST_DEC_LOOP performance test, I found the
offset check is much more than v1.8.3

You will see the condition check difference via lzbench with dickens test case.
v1.8.3 34959
v.1.9.x 1055885

After investigate the code, we could see the difference.
v.1.8.3 SKIP the condition check if
if condition is true in:
https://github.com/lz4/lz4/blob/v1.8.3/lib/lz4.c#L1463
AND below condition is true
https://github.com/lz4/lz4/blob/v1.8.3/lib/lz4.c#L1478\
The offset check should be invoked.

v1.9.3
The offset check code will be invoked in every loop which lead to downgrade.
So the fix would be move this check to specific condition
to avoid useless condition check.

After this change, the call number is same as v1.8.3
2019-05-31 08:36:13 +08:00
Yann Collet
676d46df27 updated LZ4_DECOMPRESS_INPLACE_MARGIN
to pass worst case scenario.
Now adds margin proportional to input size to counter local expansion.
2019-05-30 16:19:30 -07:00
Yann Collet
22adbb176a add more doc on in-place (de)compression 2019-05-30 09:45:21 -07:00
Yann Collet
76116495bf some more minor conversion warnings fixes 2019-05-29 13:14:52 -07:00
Yann Collet
444550defa ensure lz4.h can be included with or without LZ4_STATIC_LINKING_ONLY in any order
ensure correct propagation of LZ4_DISTANCE_MAX
2019-05-29 12:21:14 -07:00
Yann Collet
b17f578a91 added comments and macros for in-place (de)compression 2019-05-29 12:06:13 -07:00
Niko Dzhus
2be2fe43a8 fix temporary buffer use when input size hint is respected 2019-05-24 22:08:44 +03:00
Yann Collet
a7151324af
Merge pull request #708 from gabrielstedman/list
Add multiframe report to --list command
2019-05-16 15:56:42 -07:00
gstedman
98a86c8ef6 Add multiframe report to --list command 2019-05-15 21:13:19 +01:00
George Prekas
605d811e6c enable LZ4_FAST_DEC_LOOP build macro on aarch64/GCC by default 2019-05-07 08:36:06 -05:00
Brenden Eng
9e056bc032 Include block checksum in worst case scenario calculation of dstCapacity 2019-04-25 22:37:39 -04:00
Yann Collet
ba99eac4d0 several minor style changes recommended by clang-tidy 2019-04-24 10:03:02 -07:00
Yann Collet
f9781a6643
Merge pull request #697 from ldv-alt/fixes/test-amalgamation
Fix test-amalgamation
2019-04-23 17:20:03 -07:00
Dmitry V. Levin
10726d4c56 test-amalgamation: use a single cat command
Use the list of prerequisites instead of listing those files manually,
this way they will never fall out of sync.

Also update the amalgamation example to use a single cat command.

Fixes: a7e8d394 ("[amalgamation] add test")
Fixes: b192c86b ("[amalgamation] lz4frame.c")
2019-04-23 21:18:11 +00:00
Chongyu Zhu
024216ef73
lib/Makefile: Fix detection of Darwin. 2019-04-24 03:13:19 +08:00
JPeterMugaas
7136489d33 More build imrpvements
Moved a few other tests to Makefiles.inc.  Other things might need to go there.
Made a test for symlink appropriateness.  Windows can NOT handle them the same way Unix-like operating systems do (if at all).  This is mostly the same as the Visual C projects.
embed version info into .dll and .exes that are redistributed.
2019-04-23 07:44:00 -04:00
Yann Collet
c4fe7a2047
Merge pull request #689 from JPeterMugaas/jpm-makefile
Jpm makefile - as described in https://github.com/lz4/lz4/issues/688
2019-04-22 15:29:50 -07:00
JPeterMugaas
2acddd9918 Fix a test for mingw 2019-04-22 16:06:04 -04:00
JPeterMugaas
b48f823f90 Try to put some tests I made in ONE place. I also moved a test for "install" in one place to try to isolate it. 2019-04-22 15:48:48 -04:00
JPeterMugaas
773b66547f Initial commits from diff I submitted earlier 2019-04-22 13:48:59 -04:00
Yann Collet
7a4e3b1fac bumped version number
to v1.9.1
2019-04-19 11:59:49 -07:00
Yann Collet
af35920c81 lz4frame: initializers compatibility with C++
fix #679, reported by @degski
2019-04-19 10:23:50 -07: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
5acfb15df0 re-enable FORCE_INLINE
was disabled for tests
2019-04-17 15:33:37 -07:00
Yann Collet
25d96f1e4d fix out-of-bound read within LZ4_decompress_fast()
and deprecate LZ4_decompress_fast(),
with deprecation warnings enabled by default.

Note that, as a consequence of the fix,
LZ4_decompress_fast is now __slower__ than LZ4_decompress_safe().
That's because, since it doesn't know the input buffer size,
it must progress more cautiously into the input buffer
to ensure to out-of-bound read.
2019-04-17 15:01:53 -07:00
Norm Green
1848ea5cbd Fix AIX errors/warnings 2019-04-17 09:20:09 -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
Yann Collet
920c988669 simplified output_directive 2019-04-15 14:13:10 -07:00
Yann Collet
55f6f0dd74 fix comma for pedantic 2019-04-15 11:22:25 -07:00
Yann Collet
474c17cdc4 unified limitedOutput_directive
between lz4.c and lz4hc.c .
was left in a strange state after the "amalgamation" patch.

Now only 3 directives remain,
same name across both implementations,
single definition place.

Might allow some light simplification due to reduced nb of states possible.
2019-04-15 11:09:56 -07:00
Yann Collet
1f4a412646 decompress*_fast() function do not generate deprecation warnings
they are classified as deprecated in the API documentation (lz4.h)
but do not yet trigger a warning,
to give time to existing applications to move away.

Also, the _fast() variants are still ~5% faster than the _safe() ones
after Dave's patch.
2019-04-15 10:33:40 -07:00
Yann Collet
481a37fe47 fixed lz4frame with linked blocks
when one block was not compressible,
it would tag the context as `dirty`,
resulting in compression automatically bailing out of all future blocks,
making the rest of the frame uncompressible.
2019-04-15 10:28:36 -07:00
Yann Collet
3215069741 Merge branch 'dev' of github.com:Cyan4973/lz4 into dev 2019-04-13 15:55:33 -07:00
Yann Collet
749c3400bd fixed incorrect assertion condition
output can use the full length of output buffer
2019-04-13 15:55:06 -07:00
Yann Collet
dd43b913a2 fix minor visual warning
yet some overly cautious overflow risk flag,
while it's actually impossible, due to previous test just one line above.
Changing the cast position, just to be please the thing.
2019-04-12 16:56:22 -07:00
Yann Collet
f8b7605034 fixed minor Visual warnings
since Visual 2017,
worries about potential overflow, which are actually impossible.
Replaced (c * a) by (c ? a : 0).
Will likely replaced a * by a cmov.
Probably harmless for performance.
2019-04-12 16:49:01 -07:00
Yann Collet
21ff1a839a updated doc to underline difference between block and frame
as this is a very frequent source of confusion for new users.
2019-04-12 11:27:44 -07:00
Yann Collet
bcb26565a7 improved documentation for LZ4 dictionary compression 2019-04-11 15:20:46 -07:00
Yann Collet
8d76c8a44a introduce LZ4_DISTANCE_MAX build macro
make it possible to generate LZ4-compressed block
with a controlled maximum offset (necessarily <= 65535).

This could be useful for compatibility with decoders
using a very limited memory budget (<64 KB).

Answer #154
2019-04-11 14:15:33 -07:00
Yann Collet
5580f4333a
Merge pull request #663 from lz4/headerSize
made LZ4F_getHeaderSize() public
2019-04-09 21:30:14 -07:00
Yann Collet
db60ed19b1 added versions in comments 2019-04-09 18:23:32 -07:00
Yann Collet
9e501702bd made LZ4F_getHeaderSize() public 2019-04-09 18:10:58 -07:00
Yann Collet
d8d5f14138 fixed loadDictHC
by making a full initialization
instead of a fast reset.
2019-04-09 15:37:59 -07:00
Yann Collet
887e8a4d01 re-enable LZ4_resetStreamHC()
towards deprecation, but still available and fully supported
2019-04-09 14:00:30 -07:00
Yann Collet
14c71dfa9c modified LZ4_initStreamHC() to look like LZ4_initStream()
it is now a pure initializer, for statically allocated states.
It can initialize any memory area, and because of this, requires size.
2019-04-09 13:55:42 -07:00
Yann Collet
5ef4f3ce91 check some more initialization result
ensure it's not NULL.
2019-04-08 16:51:22 -07:00
Yann Collet
111df0fa45 removed LZ4_stream_t alignment test on Visual
it fails on x86 32-bit mode :
Visual reports an alignment of 8-bytes (even with alignof())
but actually only align LZ4_stream_t on 4 bytes.
The alignment check then fails, resulting in missed initialization.
2019-04-08 16:47:21 -07:00
Yann Collet
c198a39a66 LZ4_initStream() checks alignment restriction
updated associated documentation
2019-04-08 12:49:54 -07:00
Yann Collet
34f0004a5e added comment on initStream + _extState_
as suggested by @felixhandte
2019-04-05 15:35:19 -07:00
Yann Collet
2ece0d8380 created LZ4_initStream()
- promoted LZ4_resetStream_fast() to stable
- moved LZ4_resetStream() into deprecate, but without triggering a compiler warning
- update all sources to no longer rely on LZ4_resetStream()

note : LZ4_initStream() proposal is slightly different :
it's able to initialize any buffer, provided that it's large enough.
To this end, it accepts a void*, and returns an LZ4_stream_t*.
2019-04-05 12:56:26 -07:00
Yann Collet
c3f8928f87 fixed strict iso C90 2019-04-05 10:41:26 -07:00
Yann Collet
c491df54ec created LZ4_initStreamHC()
- promoted LZ4_resetStreamHC_fast() to stable
- moved LZ4_resetStreamHC() to deprecated (but do not generate a warning yet)
- Updated doc, to highlight difference between init and reset
- switched all invocations of LZ4_resetStreamHC() onto LZ4_initStreamHC()
- misc: ensure `make all` also builds /tests
2019-04-04 17:05:11 -07:00
Yann Collet
7a39fb8fb6 make _fast*() decoder generate a deprecation warning
updated modification
2019-04-04 12:47:36 -07:00
Yann Collet
ab91300509 moved LZ4_decompress_fast*() into deprecated section 2019-04-04 12:24:46 -07:00
Yann Collet
b5bedefabe fixed an old bug in LZ4F_flush()
which remained undetected so far,
as it requires a fairly large number of conditions to be triggered,
starting with enabling Block checksum, which is disabled by default,
and which usage is known to be extremely rare.
2019-04-03 16:28:42 -07:00
Yann Collet
50f01d881d fixed doc
and bumped version number fo v1.9.0
2019-04-03 14:27:21 -07:00
Yann Collet
25da6cc967 moved _destSize() into "stable API" status
as requested in #642
2019-04-03 14:18:00 -07:00
Yann Collet
f2755c9887 minor comments and reformatting 2019-04-03 08:59:29 -07:00
Yann Collet
753076bfa4 fixed minor conversion warnings 2019-04-02 17:16:43 -07:00
Yann Collet
2589c4424f created LZ4_FAST_DEC_LOOP build macro 2019-04-02 16:22:11 -07:00
Yann Collet
7d9d00f4df fixed a few minor conversion warnings 2019-04-02 16:06:37 -07:00
Yann Collet
c438548312
Merge pull request #652 from vtorri/dev
Allow installation of lz4 for Windows 10 with MSYS2
2019-03-03 13:40:45 -08:00
Vincent Torri
0360981f68 Allow installation of lz4 for Windows 10 with MSYS2 2019-03-03 22:06:38 +01:00
Yann Collet
d85bdb4ff2
Merge pull request #645 from djwatson/optimize_decompress_generic
Optimize decompress generic
2019-02-11 16:58:53 -08:00
Dave Watson
5d7d1166cb decompress_generic: Limit fastpath to x86
New fastpath currently shows a regression on qualcomm
arm chips.  Restrict it to x86 for now
2019-02-11 11:44:51 -08:00
Dave Watson
75fb878a90 decompress_generic: Add fastpath for small offsets
For small offsets of size 1, 2, 4 and 8, we can set a single uint64_t,
and then use it to do a memset() variation.  In particular, this makes
the somewhat-common RLE (offset 1) about 2-4x faster than the previous
implementation - we avoid not only the load blocked by store, but also
avoid the loads entirely.
2019-02-08 13:57:23 -08:00
Dave Watson
faac110e20 decompress_generic: Unroll loops a bit more
Generally we want our wildcopy loops to look like the
memcpy loops from our libc, but without the final byte copy checks.
We can unroll a bit to make long copies even faster.

The only catch is that this affects the value of FASTLOOP_SAFE_DISTANCE.
2019-02-08 13:57:23 -08:00
Dave Watson
1fbaf84306 decompress_generic: remove msan write
This store is also causing load-blocked-by-store issues, remove it.
The msan warning will have to be fixed another way if it is still an issue.
2019-02-08 13:57:23 -08:00
Dave Watson
28b824921d decompress_generic: re-add fastpath
This is the remaineder of the original 'shortcut'.  If true, we can avoid
the loop in LZ4_wildCopy, and directly copy instead.
2019-02-08 13:57:23 -08:00
Dave Watson
232f1e261f decompress_generic: drop partial copy check in fast loop
We've already checked that we are more than FASTLOOP_SAFE_DISTANCE
away from the end, so this branch can never be true, we will have
already jumped to the second decode loop.
2019-02-08 13:57:23 -08:00
Dave Watson
59332a3026 decompress_generic: Optimize literal copies
Use LZ4_wildCopy16 for variable-length literals.  For literal counts that
fit in the flag byte, copy directly.  We can also omit oend checks for
roughly the same reason as the previous shortcut:  We check once that both
match length and literal length fit in FASTLOOP_SAFE_DISTANCE, including
wildcopy distance.
2019-02-08 13:57:23 -08:00