Commit Graph

152 Commits

Author SHA1 Message Date
Yann Collet
03f006a7ea make scan-build accept assert() 2020-10-01 10:48:22 -07:00
Yann Collet
fe74eb2031 added memcpy() related SA warning fixes
memcpy() on NULL is UB, even if length is 0.
2020-09-30 21:20:07 -07:00
Yann Collet
392809d66e fix minor static analyzer warnings
detected by scan-build and cppcheck
fix #786
2020-09-29 17:09:58 -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
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
Christopher Harvie
57c35511d4 fix LZ4F_compressBound when automatic flushing is enabled 2020-05-13 21:48:12 -04: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
Niko Dzhus
2be2fe43a8 fix temporary buffer use when input size hint is respected 2019-05-24 22:08:44 +03:00
gstedman
98a86c8ef6 Add multiframe report to --list command 2019-05-15 21:13:19 +01:00
Brenden Eng
9e056bc032 Include block checksum in worst case scenario calculation of dstCapacity 2019-04-25 22:37:39 -04:00
Yann Collet
af35920c81 lz4frame: initializers compatibility with C++
fix #679, reported by @degski
2019-04-19 10:23:50 -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
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
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
9e501702bd made LZ4F_getHeaderSize() public 2019-04-09 18:10:58 -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
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
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
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
Tim Zakian
8193742251 Make LZ4F_getBlockSize public and publis in experimental section 2019-01-09 10:49:49 -08:00
Bing Xu
b192c86ba4 [amalgamation] lz4frame.c 2018-11-26 11:30:15 -08:00
Yann Collet
6902fa4892 fixed #589
following recommendations by @raggi.

The fix is slightly different, but achieves the same goal,
and is backed by a test tool which proves that it works
(generates the error before the patch, no longer after the patch).
2018-10-09 14:37:51 -07:00
Yann Collet
e07a37d712 added a test for LZ4F_compressEnd()
which actively tries to make it write out of bound.
For this scenario to be possible,
it's necessary to set dstCapacity < LZ4F_compressBound()

When a compression operation fails,
the CCtx context is left in an undefined state,
therefore compression cannot resume.
As a consequence :
- round trip tests must be aborted, since there is nothing valid to decompress
- most users avoid this situation, by ensuring that dstCapacity >= LZ4F_compressBound()

For these reasons, this use case was poorly tested up to now.
2018-10-09 14:25:18 -07:00
Yann Collet
21120549a7 fixed improper hint
when LZ4F_decompress() decodes an uncompressed block,
it provides an incorrect hint for next block
when frame checksum is enabled and block checksum is not.

Impact is low : the hint is just an hint,
the decoder works whatever the amount of input provided.

But the assumption that each call to LZ4F_decompress()
would generate just one complete block if input size hint was respected
was broken by this error.
2018-09-28 14:57:50 -07:00
Yann Collet
8bea19d57c fixed minor cppcheck warnings in lib 2018-09-18 15:51:26 -07:00
Yann Collet
86023f01f2 avoid final trailing comma for enum lists
as detected in #485 by @JoachimSchneider.

Refactored the c_standards tests
so that these issues get automatically detected in CI tests.
2018-09-13 14:29:41 -07:00
Jennifer Liu
e778db373b Fixed bugs about incorrect acceleration calculation and benchmarking negative compresion level 2018-06-27 13:36:38 -07:00
Yann Collet
d7b6c726ed small extDict : fixed side-effect
don't fix dictionaries of size 0.
setting dictEnd == source triggers prefix mode,
thus removing possibility to use CDict.
2018-05-05 19:59:00 -07:00
Yann Collet
af12733467 fixed frametest error
The error can be reproduced using following command :
./frametest -v -i100000000 -s1659 -t31096808

It's actually a bug in the stream LZ4 API,
when starting a new stream
and providing a first chunk to complete with size < MINMATCH.
In which case, the chunk becomes a dictionary.
No hash was generated and stored,
but the chunk is accessible as default position 0 points to dictStart,
and position 0 is still within MAX_DISTANCE.
Then, next attempt to read 32-bits from position 0 fails.

The issue would have been mitigated by starting from index 64 KB,
effectively eliminating position 0 as too far away.

The proper fix is to eliminate such "dictionary" as too small.
Which is what this patch does.
2018-05-05 18:24:11 -07:00
Yann Collet
f3e84ffd41
Merge pull request #529 from felixhandte/lz4f-fast-reset-for-streaming-only
LZ4F: Only Reset the LZ4_stream_t when Init'ing a Streaming Block
2018-05-03 15:37:51 -07:00
W. Felix Handte
5406c2e479 Only Reset the LZ4 Stream when Init'ing a Streaming Block 2018-05-03 00:03:20 -04:00
Yann Collet
c25eb16666 random lz4f clarifications
the initial intention was to update lz4f ring buffer strategy,
but lz4f doesn't use ring buffer.
Instead, it uses the destination buffer as much as possible,
and merely copies just what's required to preserve history
into its own buffer, at the end.
Pretty efficient.

This patch just clarifies a few comments and add some assert().
It's built on top of #528.

It also updates doc.
2018-05-02 16:05:42 -07:00
Yann Collet
1e6ca25af3
Merge pull request #520 from felixhandte/frame-dict-nits
Minor Fixes to Dictionary Preparation in LZ4 Frame
2018-04-27 13:52:30 -07:00
Yann Collet
47d70e755e
Merge pull request #519 from lz4/fdParser
Faster decoding speed
2018-04-27 11:46:29 -07:00
W. Felix Handte
fefc40fc0a Avoid Possibly Redundant Table Clears When Loading HC Dict 2018-04-27 14:10:27 -04:00
W. Felix Handte
5076aa3e35 Remove Redundant LZ4_resetStream() Call 2018-04-27 13:59:02 -04:00
W. Felix Handte
7d11e34413 Rename LZ4F_applyCDict() -> LZ4F_initStream() 2018-04-27 13:57:10 -04:00
Yann Collet
0fb3a3b199 fixed a number of minor cast warnings 2018-04-26 18:08:28 -07:00
Yann Collet
5c7d3812d9 fasterDecSpeed can be triggered from cli with --favor-decSpeed 2018-04-26 15:49:32 -07:00
Yann Collet
3792d00168 favorDecSpeed feature can be triggered from lz4frame
and lz4hc.
2018-04-26 15:18:44 -07:00
W. Felix Handte
a2edeac201 Limit Dictionary Size During LZ4F Decompression
Fixes lz4/lz4#517.
2018-04-26 17:18:40 -04:00
W. Felix Handte
2dfc7cbe82 Change Over Includes in the Project 2018-04-24 16:22:28 -04:00
W. Felix Handte
5ed1463bf4 Remove Debug Log Statements 2018-04-24 11:58:51 -04:00
W. Felix Handte
d7347f9eea Add API for Attaching Dictionaries 2018-04-20 14:59:34 -04:00
W. Felix Handte
0a2abacd90 Use Fast Reset in LZ4F Again 2018-04-19 20:54:35 -04:00
W. Felix Handte
61c7ceffed Use Fast Reset API in LZ4F 2018-04-19 20:54:35 -04:00
W. Felix Handte
6289ff4fb1 Call LZ4F_applyCDict Even on NULL CDict 2018-04-19 20:54:35 -04:00
W. Felix Handte
fdeead0b09 Set dictCtx Rather than memcpy'ing Ctx 2018-04-19 20:54:35 -04:00