aboutsummaryrefslogtreecommitdiff
path: root/lib/lz4.c
diff options
context:
space:
mode:
authorW. Felix Handte <w@felixhandte.com>2018-04-17 14:01:44 -0400
committerW. Felix Handte <w@felixhandte.com>2018-04-17 14:09:00 -0400
commitaedc44780468c11d90114bc1d6124af545bfc652 (patch)
treede5331577da76bb68ea14129f26d822765e5a3dc /lib/lz4.c
parent27f52724dc2dd8f7384965804c2d747f3b0dd9b4 (diff)
downloadlz4-aedc44780468c11d90114bc1d6124af545bfc652.tar.gz
Always Bump Offset by 64 KB in LZ4_loadDict()
This actually ensures the guarantee referred to in the comment in LZ4_compress_fast_continue().
Diffstat (limited to 'lib/lz4.c')
-rw-r--r--lib/lz4.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 4b0efb14..0ce05dae 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -1173,11 +1173,18 @@ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize)
LZ4_prepareTable(dict, 0, tableType);
+ /* We always increment the offset by 64 KB, since, if the dict is longer,
+ * we truncate it to the last 64k, and if it's shorter, we still want to
+ * advance by a whole window length so we can provide the guarantee that
+ * there are only valid offsets in the window, which allows an optimization
+ * in LZ4_compress_fast_continue() where it uses noDictIssue even when the
+ * dictionary isn't a full 64k. */
+
if ((dictEnd - p) > 64 KB) p = dictEnd - 64 KB;
- base = p - dict->currentOffset;
+ base = dictEnd - 64 KB - dict->currentOffset;
dict->dictionary = p;
dict->dictSize = (U32)(dictEnd - p);
- dict->currentOffset += dict->dictSize;
+ dict->currentOffset += 64 KB;
dict->tableType = tableType;
if (dictSize < (int)HASH_UNIT) {