summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2018-09-11 00:36:40 (GMT)
committerYann Collet <cyan@fb.com>2018-09-11 17:00:13 (GMT)
commit6d32240b2e9cb921f9b34b790d787d0ee1ea51cb (patch)
tree2e4f1bb6f3f3ec035365e441079e37aed43e153d
parentb87a8e9e623d6e2404ae9f948a4e0ee8f1415bee (diff)
downloadlz4-6d32240b2e9cb921f9b34b790d787d0ee1ea51cb.zip
lz4-6d32240b2e9cb921f9b34b790d787d0ee1ea51cb.tar.gz
lz4-6d32240b2e9cb921f9b34b790d787d0ee1ea51cb.tar.bz2
clarify constant MFLIMIT
and separate it from MATCH_SAFEGUARD_DISTANCE. While both constants have same value, they do not seve same purpose, hence should not be confused.
-rw-r--r--lib/lz4.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 133501d..4046102 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -297,8 +297,9 @@ void LZ4_wildCopy(void* dstPtr, const void* srcPtr, void* dstEnd)
#define MINMATCH 4
#define WILDCOPYLENGTH 8
-#define LASTLITERALS 5
-#define MFLIMIT (WILDCOPYLENGTH+MINMATCH)
+#define LASTLITERALS 5 /* see ../doc/lz4_Block_format.md#parsing-restrictions */
+#define MFLIMIT 12 /* see ../doc/lz4_Block_format.md#parsing-restrictions */
+#define MATCH_SAFEGUARD_DISTANCE ((2*WILDCOPYLENGTH) - MINMATCH) /* ensure it's possible to write 2 x wildcopyLength without overflowing output buffer */
static const int LZ4_minLength = (MFLIMIT+1);
#define KB *(1 <<10)
@@ -1588,7 +1589,7 @@ _copy_match:
/* partialDecoding : may not respect endBlock parsing restrictions */
assert(op<=oend);
- if (partialDecoding && (cpy > oend-12)) {
+ if (partialDecoding && (cpy > oend-MATCH_SAFEGUARD_DISTANCE)) {
size_t const mlen = MIN(length, (size_t)(oend-op));
const BYTE* const matchEnd = match + mlen;
BYTE* const copyEnd = op + mlen;
@@ -1616,7 +1617,7 @@ _copy_match:
}
op += 8;
- if (unlikely(cpy > oend-12)) {
+ if (unlikely(cpy > oend-MATCH_SAFEGUARD_DISTANCE)) {
BYTE* const oCopyLimit = oend - (WILDCOPYLENGTH-1);
if (cpy > oend-LASTLITERALS) goto _output_error; /* Error : last LASTLITERALS bytes must be literals (uncompressed) */
if (op < oCopyLimit) {