diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2018-02-26 20:29:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-26 20:29:54 (GMT) |
commit | 1882b10e4192b993dd40361d4df1ef391c168911 (patch) | |
tree | 4701389655ac1f1b10eea0e38aa7fcd6fc37336c | |
parent | 99c26729b59d0389734973a9e3c55f7ef8408efb (diff) | |
parent | 7173a631db61ab9535bd0d6e5e00e9dc081d4df3 (diff) | |
download | lz4-1882b10e4192b993dd40361d4df1ef391c168911.zip lz4-1882b10e4192b993dd40361d4df1ef391c168911.tar.gz lz4-1882b10e4192b993dd40361d4df1ef391c168911.tar.bz2 |
Merge pull request #476 from lz4/mflimit
edge case fix : compress up to end-mflimit (12 bytes)
-rw-r--r-- | lib/lz4.c | 7 | ||||
-rw-r--r-- | lib/lz4hc.c | 6 | ||||
-rw-r--r-- | lib/lz4opt.h | 6 |
3 files changed, 10 insertions, 9 deletions
@@ -545,7 +545,7 @@ LZ4_FORCE_INLINE int LZ4_compress_generic( const ptrdiff_t dictDelta = dictEnd - (const BYTE*)source; const BYTE* anchor = (const BYTE*) source; const BYTE* const iend = ip + inputSize; - const BYTE* const mflimit = iend - MFLIMIT; + const BYTE* const mflimitPlusOne = iend - MFLIMIT + 1; const BYTE* const matchlimit = iend - LASTLITERALS; BYTE* op = (BYTE*) dest; @@ -594,7 +594,8 @@ LZ4_FORCE_INLINE int LZ4_compress_generic( forwardIp += step; step = (searchMatchNb++ >> LZ4_skipTrigger); - if (unlikely(forwardIp > mflimit)) goto _last_literals; + if (unlikely(forwardIp > mflimitPlusOne)) goto _last_literals; + assert(ip < mflimitPlusOne); match = LZ4_getPositionOnHash(h, cctx->hashTable, tableType, base); if (dict==usingExtDict) { @@ -680,7 +681,7 @@ _next_match: anchor = ip; /* Test end of chunk */ - if (ip > mflimit) break; + if (ip >= mflimitPlusOne) break; /* Fill table */ LZ4_putPosition(ip-2, cctx->hashTable, tableType, base); diff --git a/lib/lz4hc.c b/lib/lz4hc.c index f3631c5..726cfaa 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -425,7 +425,7 @@ static int LZ4HC_compress_hashChain ( if (inputSize < LZ4_minLength) goto _last_literals; /* Input too small, no compression (all literals) */ /* Main Loop */ - while (ip < mflimit) { + while (ip <= mflimit) { ml = LZ4HC_InsertAndFindBestMatch (ctx, ip, matchlimit, &ref, maxNbAttempts, patternAnalysis); if (ml<MINMATCH) { ip++; continue; } @@ -435,7 +435,7 @@ static int LZ4HC_compress_hashChain ( ml0 = ml; _Search2: - if (ip+ml < mflimit) + if (ip+ml <= mflimit) ml2 = LZ4HC_InsertAndGetWiderMatch(ctx, ip + ml - 2, ip + 0, matchlimit, ml, &ref2, &start2, maxNbAttempts, patternAnalysis); @@ -482,7 +482,7 @@ _Search3: } /* Now, we have start2 = ip+new_ml, with new_ml = min(ml, OPTIMAL_ML=18) */ - if (start2 + ml2 < mflimit) + if (start2 + ml2 <= mflimit) ml3 = LZ4HC_InsertAndGetWiderMatch(ctx, start2 + ml2 - 3, start2, matchlimit, ml2, &ref3, &start3, maxNbAttempts, patternAnalysis); diff --git a/lib/lz4opt.h b/lib/lz4opt.h index 5a8438c..9bd4822 100644 --- a/lib/lz4opt.h +++ b/lib/lz4opt.h @@ -127,7 +127,7 @@ static int LZ4HC_compress_optimal ( /* Main Loop */ assert(ip - anchor < LZ4_MAX_INPUT_SIZE); - while (ip < mflimit) { + while (ip <= mflimit) { int const llen = (int)(ip - anchor); int best_mlen, best_off; int cur, last_match_pos = 0; @@ -186,7 +186,7 @@ static int LZ4HC_compress_optimal ( const BYTE* const curPtr = ip + cur; LZ4HC_match_t newMatch; - if (curPtr >= mflimit) break; + if (curPtr > mflimit) break; DEBUGLOG(7, "rPos:%u[%u] vs [%u]%u", cur, opt[cur].price, opt[cur+1].price, cur+1); if (fullUpdate) { @@ -314,7 +314,7 @@ encode: /* cur, last_match_pos, best_mlen, best_off must be set */ if ( LZ4HC_encodeSequence(&ip, &op, &anchor, ml, ip - offset, limit, oend) ) /* updates ip, op and anchor */ goto _dest_overflow; } } - } /* while (ip < mflimit) */ + } /* while (ip <= mflimit) */ _last_literals: /* Encode Last Literals */ |