diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2019-07-15 23:38:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-15 23:38:28 (GMT) |
commit | 81a14ccccb121281ea5a433ef677484deaef1cfb (patch) | |
tree | cc41ddbff1fe2aaf4d35fe12516f5a697f99fd7a /lib | |
parent | a23541463d924f11dfc0843f4ddb10a1e777e405 (diff) | |
parent | 6654c2cd3bd49dfc6b6bb3447bcc01799ea35ac3 (diff) | |
download | lz4-81a14ccccb121281ea5a433ef677484deaef1cfb.zip lz4-81a14ccccb121281ea5a433ef677484deaef1cfb.tar.gz lz4-81a14ccccb121281ea5a433ef677484deaef1cfb.tar.bz2 |
Merge pull request #755 from lz4/custom_distance
ensure conformance with custom LZ4_DISTANCE_MAX
Diffstat (limited to 'lib')
-rw-r--r-- | lib/README.md | 4 | ||||
-rw-r--r-- | lib/lz4.c | 13 |
2 files changed, 11 insertions, 6 deletions
diff --git a/lib/README.md b/lib/README.md index cf1505f..cba2c34 100644 --- a/lib/README.md +++ b/lib/README.md @@ -56,8 +56,8 @@ The following build macro can be selected at compilation time : - `LZ4_DISTANCE_MAX` : control the maximum offset that the compressor will allow. Set to 65535 by default, which is the maximum value supported by lz4 format. Reducing maximum distance will reduce opportunities for LZ4 to find matches, - hence will produce worse the compression ratio. - However, a smaller max distance may allow compatibility with specific decoders using limited memory budget. + hence will produce a worse compression ratio. + However, a smaller max distance can allow compatibility with specific decoders using limited memory budget. This build macro only influences the compressed output of the compressor. - `LZ4_DISABLE_DEPRECATE_WARNINGS` : invoking a deprecated function will make the compiler generate a warning. @@ -413,7 +413,8 @@ static const int LZ4_minLength = (MFLIMIT+1); #define MB *(1 <<20) #define GB *(1U<<30) -#if (LZ4_DISTANCE_MAX > 65535) /* max supported by LZ4 format */ +#define LZ4_DISTANCE_ABSOLUTE_MAX 65535 +#if (LZ4_DISTANCE_MAX > LZ4_DISTANCE_ABSOLUTE_MAX) /* max supported by LZ4 format */ # error "LZ4_DISTANCE_MAX is too big : must be <= 65535" #endif @@ -915,10 +916,14 @@ LZ4_FORCE_INLINE int LZ4_compress_generic( forwardH = LZ4_hashPosition(forwardIp, tableType); LZ4_putIndexOnHash(current, h, cctx->hashTable, tableType); + DEBUGLOG(7, "candidate at pos=%u (offset=%u \n", matchIndex, current - matchIndex); if ((dictIssue == dictSmall) && (matchIndex < prefixIdxLimit)) { continue; } /* match outside of valid area */ assert(matchIndex < current); - if ((tableType != byU16) && (matchIndex+LZ4_DISTANCE_MAX < current)) { continue; } /* too far */ - if (tableType == byU16) { assert((current - matchIndex) <= LZ4_DISTANCE_MAX); } /* too_far presumed impossible with byU16 */ + if ( ((tableType != byU16) || (LZ4_DISTANCE_MAX < LZ4_DISTANCE_ABSOLUTE_MAX)) + && (matchIndex+LZ4_DISTANCE_MAX < current)) { + continue; + } /* too far */ + assert((current - matchIndex) <= LZ4_DISTANCE_MAX); /* match now expected within distance */ if (LZ4_read32(match) == LZ4_read32(ip)) { if (maybe_extMem) offset = current - matchIndex; @@ -1082,7 +1087,7 @@ _next_match: LZ4_putIndexOnHash(current, h, cctx->hashTable, tableType); assert(matchIndex < current); if ( ((dictIssue==dictSmall) ? (matchIndex >= prefixIdxLimit) : 1) - && ((tableType==byU16) ? 1 : (matchIndex+LZ4_DISTANCE_MAX >= current)) + && (((tableType==byU16) && (LZ4_DISTANCE_MAX == LZ4_DISTANCE_ABSOLUTE_MAX)) ? 1 : (matchIndex+LZ4_DISTANCE_MAX >= current)) && (LZ4_read32(match) == LZ4_read32(ip)) ) { token=op++; *token=0; |