Commit Graph
100 Commits
Author SHA1 Message Date
Nick Terrell 08981d2638 [lib] Allow compression dictionaries with missing symbols
Allow compression to use dictionaries with missing symbols in their
entropy tables. We set the FSE repeat mode to check when there are
missing symbols, and set the FSE repeat mode to valid when all symbols
are present.

Note that when not all symbols are present, the heuristics which favor
dictionary tables for lower compression levels won't activate.

Tested by manually creating a dictionary with missing symbols of every
type, and validing that the compressor rejects it before this change,
and accepts it after this change. Also, I ran the `dictionary_loader`
fuzzer for >1 hour of CPU time without running into cases where
compression succeeds, but decompression fails.

Fixes #2174.
2020-06-12 17:57:19 -07:00
Nick TerrellandGitHub 9eb2ccc9fb Merge pull request #2167 from terrelln/pzstd-ms-fix
[pzstd] Fix compilation error in MinGW
2020-05-22 23:38:27 -07:00
Nick Terrell 5aa5aa4df7 [pzstd] Fix compilation error in MinGW 2020-05-22 22:26:02 -07:00
Nick Terrell 651d3d73e0 [test] Update the ldm loadedDictEnd test to cover zstdmt 2020-05-19 16:14:14 -07:00
Nick Terrell 3cc227e90e [ldm][mt] Fix loadedDictEnd 2020-05-19 15:55:03 -07:00
Nick TerrellandGitHub 0dcd3eec43 Merge pull request #2152 from terrelln/simple-rt-bound
[fuzz] Expand the allowedExpansion
2020-05-19 12:56:11 -07:00
Nick Terrell b82bf711fc [fuzz] Expand the allowedExpansion 2020-05-19 11:42:53 -07:00
Nick TerrellandGitHub 9778f46014 Merge pull request #2150 from terrelln/ldm-dict-reset
[ldm] Reset loadedDictEnd when the context is reset
2020-05-18 18:33:01 -07:00
Nick Terrell 7b317b4876 [test] Test that the ldm dictionary gets invalidated on reset 2020-05-18 16:00:28 -07:00
Nick Terrell 87dbd6d4bf [test] Improve LDM forceMaxWindow test 2020-05-18 15:11:18 -07:00
Nick Terrell b2092c6dc4 [ldm] Reset loadedDictEnd when the context is reset 2020-05-18 12:35:44 -07:00
Nick Terrell 608075abb2 [test][regression] Update results.csv 2020-05-14 17:06:39 -07:00
Nick TerrellandGitHub 9ff4991d73 Merge pull request #2138 from terrelln/ldm-fix
[lib] Fix bug in loading LDM dictionary in MT mode
2020-05-14 13:32:00 -07:00
Nick Terrell bf0591e1e2 [test] Expose the LDM+MT+dict bug in a unit test 2020-05-14 12:06:55 -07:00
Nick Terrell add7ed2d4a [lib] Fix bug in loading LDM dictionary in MT mode
Exposed when loading a dictionary < LDM minMatch bytes in MT mode.

Test Plan:
```
CC=clang make -j zstreamtest MOREFLAGS="-O0 -fsanitize=address"
./zstreamtest -vv -i100000000 -t1 --newapi -s7065 -t3925297
```

TODO: Add an explicit test that loads a small dictionary in MT mode
2020-05-14 11:52:28 -07:00
Nick Terrell 70c80e19e6 [greedy] Fix performance instability 2020-05-12 17:51:16 -07:00
Nick TerrellandGitHub c3e921c639 Merge pull request #2131 from terrelln/raw-dict-fuzzer
Fix rare scenario with lazy parser, dictionary, and repcodes
2020-05-12 17:44:31 -07:00
Nick Terrell f800e72a3c [lib] Fix assertion when dictionary is prefix 2020-05-12 14:33:59 -07:00
Nick Terrell 3c1eba4d99 [lib] Fix lazy repcode validity checks 2020-05-12 12:25:06 -07:00
Nick Terrell 4e0515916d [lib] Fix repcode validation in no dict mode 2020-05-12 11:57:15 -07:00
Nick Terrell 6d687a8816 [lib] Fix dictionary + repcodes + optimal parser 2020-05-12 10:36:53 -07:00
Nick Terrell 4b88bd3ee0 [lib][fuzz] Assert sequences are valid in round trip tests 2020-05-11 20:38:49 -07:00
Nick Terrell 80d3585e31 [lib] Fix lazy parser with dictionary + repcodes 2020-05-11 19:04:30 -07:00
Nick Terrell 1185dfb8d1 [fuzz] Add raw dictionary content fuzzer 2020-05-11 19:03:33 -07:00
Nick Terrell 301a62fe08 [fuzz] Fix compress bound for dictionary_round_trip 2020-05-11 19:00:52 -07:00
Nick TerrellandGitHub 738f49178b Merge pull request #2128 from terrelln/benches
Update benchmarks and add fast mode
2020-05-11 13:53:18 -07:00
Nick Terrell f2f86b50ae Update benchmarks and add fast mode 2020-05-11 12:36:36 -07:00
Nick TerrellandGitHub 32b5a8ec41 Merge pull request #2118 from Artoria2e5/patch-1
programs/README.md: update help text
2020-05-08 11:13:44 -07:00
Nick TerrellandNick Terrell 45c66dd298 [zdict] Stabilize ZDICT_finalizeDictionary() 2020-05-07 10:37:01 -07:00
Nick TerrellandNick Terrell 5717bd39ee [lib] Fix NULL pointer dereference
When the output buffer is `NULL` with size 0, but the frame content size
is non-zero, we will write to the NULL pointer because our bounds check
underflowed.

This was exposed by a recent PR that allowed an empty frame into the
single-pass shortcut in streaming mode.

* Fix the bug.
* Fix another NULL dereference in zstd-v1.
* Overflow checks in 32-bit mode.
* Add a dedicated test.
* Expose the bug in the dedicated simple_decompress fuzzer.
* Switch all mallocs in fuzzers to return NULL for size=0.
* Fix a new timeout in a fuzzer.

Neither clang nor gcc show a decompression speed regression on x86-64.
On x86-32 clang is slightly positive and gcc loses 2.5% of speed.

Credit to OSS-Fuzz.
2020-05-06 12:09:02 -07:00
Nick TerrellandGitHub e103d7b4a6 Fix superblock mode (#2100)
Fixes:

Enable RLE blocks for superblock mode
Fix the limitation that the literals block must shrink. Instead, when we're within 200 bytes of the next header byte size, we will just use the next one up. That way we should (almost?) always have space for the table.
Remove the limitation that the first sub-block MUST have compressed literals and be compressed. Now one sub-block MUST be compressed (otherwise we fall back to raw block which is okay, since that is streamable). If no block has compressed literals that is okay, we will fix up the next Huffman table.
Handle the case where the last sub-block is uncompressed (maybe it is very small). Before it would skip superblock in this case, now we allow the last sub-block to be uncompressed. To do this we need to regenerate the correct repcodes.
Respect disableLiteralsCompression in superblock mode
Fix superblock mode to handle a block consisting of only compressed literals
Fix a off by 1 error in superblock mode that disabled it whenever there were last literals
Fix superblock mode with long literals/matches (> 0xFFFF)
Allow superblock mode to repeat Huffman tables
Respect ZSTD_minGain().
Tests:

Simple check for the condition in #2096.
When the simple_round_trip fuzzer enables superblock mode, it checks that the compressed size isn't expanded too much.
Remaining limitations:

O(targetCBlockSize^2) because we recompute statistics every sequence
Unable to split literals of length > targetCBlockSize into multiple sequences
Refuses to generate sub-blocks that don't shrink the compressed data, so we could end up with large sub-blocks. We should emit those sections as uncompressed blocks instead.
...
Fixes #2096
2020-05-01 16:11:47 -07:00
Nick TerrellandGitHub 0ed07f6dfe Merge pull request #2094 from terrelln/stable-dst
[lib] Add ZSTD_d_stableOutBuffer + fix single-pass mode for empty frames
2020-04-28 17:53:24 -07:00
Nick Terrell 55a57d46be Add extra warnings about not modifying the ZSTD_outBuffer 2020-04-28 12:07:42 -07:00
Nick TerrellandGitHub 108a5572a5 Merge pull request #2048 from nocnokneo/ctest-support
Add CTest support
2020-04-28 11:01:13 -07:00
Nick Terrell 1343b815f8 [fuzz] Fuzz test ZSTD_d_stableOutBuffer 2020-04-27 20:04:04 -07:00
Nick Terrell 77a2945c43 Add some comments 2020-04-27 20:04:04 -07:00
Nick Terrell f33de06c3e [lib] Fix single-pass mode for empty frames 2020-04-27 20:04:01 -07:00
Nick Terrell a4ff217baf [lib] Add ZSTD_d_stableOutBuffer 2020-04-27 18:09:44 -07:00
Nick Terrell b104f8e3eb [zstd] Fix typo in ZSTD_dParameter 2020-04-27 12:12:28 -07:00
Nick TerrellandGitHub 5fcbc484c8 Merge pull request #2040 from caoyzh/dev-2
Optimize by prefetching on aarch64
2020-04-08 13:14:47 -07:00
Nick TerrellandGitHub 1665462573 Merge pull request #2054 from terrelln/license-fix
Standardize and fix copyright and licenses
2020-03-27 11:00:01 -07:00
Nick TerrellandGitHub 8fda220d70 Merge pull request #2053 from terrelln/fix-play-test
[test] Fix playTests.sh with space in binary path
2020-03-26 21:08:10 -07:00
Nick Terrell c7ae28a67d [circleci] Run test-license.py
Run it first because it is very fast (~1 second)
2020-03-26 20:13:16 -07:00
Nick Terrell ef9e6fe227 [test] Fix playTests.sh with space in binary path
playTests.sh didn't work when `ZSTD_BIN` or `DATAGEN_BIN` had a space in
the path name. This happens for me because I split the cmake build
directory by compiler name, like "Clang 9.0.0".

The fix is to replace all instances of `$ZSTD` with the `zstd()`
function, and the replace `$DATAGEN` with `datagen()`. This will allow
us to change how we call zstd/datagen in the future without having to
change every callsite.
2020-03-26 19:52:19 -07:00
Nick Terrell 1f144351b7 [test] Add a test that checks for valid copyright and licenses
Tests all `.h`, `.c`, `.py`, and `Makefile` files for valid copyright
and license lines. Excludes a small number of exceptions (threading, and
divsufsort).

* Copyright does not contains `present`
* Copyright contains `Facebook, Inc`
* Copyright contains the current year
* License contains exactly the lines we expect
2020-03-26 17:02:09 -07:00
Nick Terrell ac58c8d720 Fix copyright and license lines
* All copyright lines now have -2020 instead of -present
* All copyright lines include "Facebook, Inc"
* All licenses are now standardized

The copyright in `threading.{h,c}` is not changed because it comes from
zstdmt.

The copyright and license of `divsufsort.{h,c}` is not changed.
2020-03-26 17:02:06 -07:00
Nick TerrellandGitHub f5029e285f Merge pull request #2050 from terrelln/align
Align decompress sequences loop to 32+16 bytes
2020-03-24 11:42:59 -07:00
Nick Terrell 8d0ee37ac0 Align decompress sequences loop to 32+16 bytes
The alignment is added before the loop, so this shouldn't hurt
performance in any case. The only way it hurts is if there is already
performance instability, and we force it to be stable but in the bad
case.

This consistently gets us into the good case with gcc-{7,8,9} on an
Intel i9-9900K and clang-9. gcc-5 is 5% worse than its best case but has
stable performance. We get consistently good behavior on my Macbook Pro
compiled with both clang and gcc-8. It ends up in the 50% from DSB and
50% from MITE case, but the performance is the same as the 85% DSB case,
so thats fine.
2020-03-23 19:40:31 -07:00
Nick TerrellandGitHub d34204a7b7 Merge pull request #2029 from terrelln/minor-opt
[opt] Update repcodes less often
2020-03-23 18:12:32 -07:00
Nick Terrell 81fda0419e [opt] Only update repcodes upon arrival 2020-03-04 17:57:15 -08:00
Nick TerrellandGitHub 04744e52dc Merge pull request #2028 from terrelln/minor-opt
[opt] Don't recompute initial literals price
2020-03-04 17:40:59 -08:00
Nick Terrell 0f9882deb9 [opt] Don't recompute repcodes while emitting sequences 2020-03-04 17:23:00 -08:00
Nick Terrell c6caa2d04e [opt] Delete ZSTD_litLengthContribution 2020-03-04 16:35:26 -08:00
Nick Terrell 610171ed86 [opt] Explain why we don't include literals price 2020-03-04 16:29:19 -08:00
Nick Terrell 5f49578be7 [opt] Don't recompute initial literals price 2020-03-04 16:27:17 -08:00
Nick TerrellandGitHub 5acd074aae Merge pull request #2024 from terrelln/zstdgrep-error
[zstdgrep] Log zstd decompression errors to stderr
2020-03-02 17:49:08 -08:00
Nick Terrell dbd6439bb6 [zstdgrep] Add a simple test 2020-03-02 16:51:34 -08:00
Nick TerrellandGitHub 5fb1d64806 Merge pull request #2023 from terrelln/fix-logs
Dont log errors when ZSTD_fseBitCost() returns an error
2020-03-02 13:09:30 -08:00
Nick Terrell f589e2b5c8 [zstdgrep] Remove -f because zstdcat implies it 2020-03-02 11:30:12 -08:00
Nick Terrell 2c10bbd866 [zstdgrep] Log zstd decompression errors to stderr 2020-03-02 11:25:36 -08:00
Nick Terrell c836992be1 Dont log errors when ZSTD_fseBitCost() returns an error 2020-03-02 11:13:18 -08:00
Nick TerrellandGitHub 99b1e1e810 Merge pull request #2013 from terrelln/oss-fuzz
Update CIFuzz file and turn off dry-run mode
2020-02-24 13:53:45 -08:00
Nick Terrell 0c4ee510d5 Update CIFuzz file and turn off dry-run mode 2020-02-24 12:36:19 -08:00
Nick TerrellandGitHub ff6350c098 Merge pull request #1996 from terrelln/cifuzz-dogfood
[CIFuzz] Rename output path to artifacts
2020-02-11 12:03:43 -08:00
Nick Terrell f3414c9258 [CIFuzz] Rename output path to artifacts 2020-02-11 10:43:15 -08:00
Nick TerrellandGitHub a240a9d954 Merge pull request #1993 from terrelln/cifuzz-dogfood
Enable oss-fuzz CIFuzz dogfood
2020-02-10 12:55:58 -08:00
Nick Terrell 4de6b80c53 Enable oss-fuzz CIFuzz dogfood 2020-02-10 12:36:56 -08:00
Nick TerrellandGitHub 6a426ef65e Merge pull request #1977 from terrelln/copyless
Improve wildcopy performance across the board
2020-01-29 15:32:19 -08:00
Nick TerrellandGitHub 7627759b4e Merge pull request #1972 from terrelln/check-cont
Move ZSTD_checkContinuity() to zstd_decompress_block.c
2020-01-23 22:02:50 -08:00
Nick TerrellandGitHub e6d3a61db8 Merge pull request #1973 from terrelln/mobile-perf
Fix performance regression on aarch64 with clang
2020-01-23 22:02:32 -08:00
Nick Terrell fa6a772f38 Initialize dctx->bType to silence valgrind false positive 2020-01-23 17:54:48 -08:00
Nick Terrell cb2abc3dbe Fix performance regression on aarch64 with clang 2020-01-23 17:31:14 -08:00
Nick Terrell 6e3cd5b024 Move ZSTD_checkContinuity() to zstd_decompress_block.c 2020-01-23 12:27:39 -08:00
Nick TerrellandGitHub 2f31050a3f Merge pull request #1965 from terrelln/android-fix
Fix timefn on android
2020-01-22 15:42:50 -08:00
Nick Terrell 7ec87cfb28 Update comment in timefn 2020-01-22 11:17:30 -08:00
Nick Terrell 768adc0774 Fix timefn on android 2020-01-21 18:57:16 -08:00
Nick TerrellandGitHub db9c8af600 Merge pull request #1957 from terrelln/fix-ultra
Fix lowLimit underflow in overflow correction
2020-01-17 18:01:35 -08:00
Nick TerrellandGitHub 76e01f3555 Merge pull request #1958 from terrelln/docs
Add --single-thread to zstd --help
2020-01-17 14:46:00 -08:00
Nick TerrellandGitHub 957d59c721 Merge pull request #1950 from terrelln/ctest
[cmake] Add playTests.sh as a test
2020-01-13 16:16:25 -08:00
Nick TerrellandNick Terrell 3ed0f65158 [cmake] Add playTests.sh as a test 2020-01-13 14:16:15 -08:00
Nick TerrellandGitHub f27b4b4ec5 Merge pull request #1948 from lazka/cygwin-fix-c99-build
Fix the c99/cmake build under Cygwin/MSYS2
2020-01-13 11:35:28 -08:00
Nick TerrellandGitHub 036b30b555 Fix super block compression and stream raw blocks in decompression (#1947)
Super blocks must never violate the zstd block bound of input_size + ZSTD_blockHeaderSize. The individual sub-blocks may, but not the super block. If the superblock violates the block bound we are liable to violate ZSTD_compressBound(), which we must not do. Whenever the super block violates the block bound we instead emit an uncompressed block.

This means we increase the latency because of the single uncompressed block. I fix this by enabling streaming an uncompressed block, so the latency of an uncompressed block is 1 byte. This doesn't reduce the latency of the buffer-less API, but I don't think we really care.

* I added a test case that verifies that the decompression has 1 byte latency.
* I rely on existing zstreamtest / fuzzer / libfuzzer regression tests for correctness. During development I had several correctness bugs, and they easily caught them.
* The added assert that the superblock doesn't violate the block bound will help us discover any missed conditions (though I think I got them all).

Credit to OSS-Fuzz.
2020-01-10 18:02:11 -08:00
Nick TerrellandGitHub d1cc9d2797 [fuzz] Allow zero sized buffers for streaming fuzzers (#1945)
* Allow zero sized buffers in `stream_decompress`. Ensure that we never have two
  zero sized buffers in a row so we guarantee forwards progress.
* Make case 4 in `stream_round_trip` do a zero sized buffers call followed by
  a full call to guarantee forwards progress.
* Fix `limitCopy()` in legacy decoders.
* Fix memcpy in `zstdmt_compress.c`.

Catches the bug fixed in PR #1939
2020-01-09 11:38:50 -08:00
Nick TerrellandGitHub b77ad810c9 [fuzz] Fix regression_driver.c with directory input (#1944)
The `numFiles` variable wasn't updated, so the fuzzer didn't do anything.
I did two things to fix this:

1. Remove the `numFiles` variable entirely.
2. Error if we can't open a file and print the number of files tested.
2020-01-08 13:20:56 -08:00
Nick TerrellandGitHub 718f00ff6f Optimize decompression speed for gcc and clang (#1892)
* Optimize `ZSTD_decodeSequence()`
* Optimize Huffman decoding
* Optimize `ZSTD_decompressSequences()`
* Delete `ZSTD_decodeSequenceLong()`
2019-11-25 18:26:19 -08:00
Nick TerrellandGitHub 385a447e52 Merge pull request #1903 from terrelln/null
Fix null pointer addition
2019-11-21 17:35:06 -08:00
Nick TerrellandGitHub 0bea5d6589 Merge pull request #1901 from terrelln/ignore
Update .gitignore
2019-11-20 17:24:19 -08:00
Nick TerrellandGitHub 9cf8e67aaf Merge pull request #1896 from terrelln/test-fixes
Fix Appveyor failure
2019-11-19 12:52:51 -08:00
Nick Terrell e0d6daabac Fix Appveyor failure 2019-11-19 11:12:26 -08:00
Nick TerrellandGitHub 6a7f65117e Merge pull request #1866 from legrosbuffle/dev
Optimized loop bounds to allow the compiler to unroll the loop.
2019-11-18 16:16:30 -08:00
Nick TerrellandGitHub a839d6852c Merge pull request #1888 from senhuang42/superblocks_fixed
RLE test and re-enable RLE in main compression loop
2019-11-18 16:09:33 -08:00
Nick TerrellandGitHub 76e661fa04 Merge pull request #1889 from vtorri/dev
shared library: rename import library with .dll.a extension
2019-11-18 16:07:28 -08:00
Nick TerrellandGitHub cabbb1e99e Merge pull request #1874 from terrelln/adjust-fix
Fix parameter selection and adjustment with srcSize == 0
2019-11-08 10:57:59 -08:00
Nick Terrell 8c474f9845 Fix parameter selection and adjustment with srcSize == 0 2019-11-07 08:58:43 -08:00
Nick TerrellandGitHub 332aade370 Merge pull request #1864 from terrelln/dict-fix
Fix 2 bugs in dictionary loading
2019-11-01 20:01:12 -07:00
Nick Terrell 60205fec02 Fix 2 bugs in dictionary loading
* Silently skip dictionaries less than 8 bytes, unless using `ZSTD_dct_fullDict`.
  This changes the compressor, which silently skips dictionaries <= 8 bytes.
* Allow repcodes that are equal to the dictionary content size, since it is in bounds.
2019-11-01 16:52:07 -07:00
Nick Terrell 75e7c0d107 [fuzz] Add dictionary_loader fuzzer
* Adds the fuzzer
* Adds an additional `InputType` for the fuzzer

I ran the fuzzer for about 10 minutes and it found 2 bugs:

* Catches the original bug without any help
* Catches an additional bug with 8-byte dictionaries
2019-11-01 15:54:24 -07:00
Nick TerrellandGitHub 5c0bdde922 Merge pull request #1856 from terrelln/assert-fix
Fix assert in ZSTD_safecopy
2019-10-28 21:44:22 -07:00
Nick Terrell 9c1860861e Fix assert in ZSTD_safecopy
In the case that `op >= oend_w` it is possible that `diff < 8` because
the two buffers could be adjacent.

Credit to OSS-Fuzz, which found the bug. It isn't reproducible because
it depends on the memory layout.
2019-10-28 17:51:17 -07:00
Nick TerrellandGitHub 3c8ff35013 Merge pull request #1840 from terrelln/regression-fix
[regression] Fix the old streaming regression test
2019-10-22 17:58:31 -07:00