summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/lz4.c20
-rw-r--r--lib/lz4.h27
2 files changed, 23 insertions, 24 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 031f8c1..be6d50f 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -924,8 +924,8 @@ LZ4_FORCE_INLINE int LZ4_compress_generic(
{ unsigned const litLength = (unsigned)(ip - anchor);
token = op++;
if ((outputLimited == limitedOutput) && /* Check output buffer overflow */
- (unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > olimit)))
- goto _failure;
+ (unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > olimit)) )
+ return 0; /* cannot compress within `dst` budget. Stored indexes in hash table are nonetheless fine */
if ((outputLimited == fillOutput) &&
(unlikely(op + (litLength+240)/255 /* litlen */ + litLength /* literals */ + 2 /* offset */ + 1 /* token */ + MFLIMIT - MINMATCH /* min last literals so last match is <= end - MFLIMIT */ > olimit))) {
@@ -998,14 +998,14 @@ _next_match:
if ((outputLimited) && /* Check output buffer overflow */
(unlikely(op + (1 + LASTLITERALS) + (matchCode>>8) > olimit)) ) {
- if (outputLimited == limitedOutput)
- goto _failure;
if (outputLimited == fillOutput) {
/* Match description too long : reduce it */
U32 newMatchCode = 15 /* in token */ - 1 /* to avoid needing a zero byte */ + ((U32)(olimit - op) - 2 - 1 - LASTLITERALS) * 255;
ip -= matchCode - newMatchCode;
matchCode = newMatchCode;
}
+ if (outputLimited == limitedOutput)
+ return 0; /* cannot compress within `dst` budget. Stored indexes in hash table are nonetheless fine */
}
if (matchCode >= ML_MASK) {
*token += ML_MASK;
@@ -1098,7 +1098,7 @@ _last_literals:
lastRun -= (lastRun+240)/255;
}
if (outputLimited == limitedOutput)
- goto _failure;
+ return 0; /* cannot compress within `dst` budget. Stored indexes in hash table are nonetheless fine */
}
if (lastRun >= RUN_MASK) {
size_t accumulator = lastRun - RUN_MASK;
@@ -1120,11 +1120,6 @@ _last_literals:
result = (int)(((char*)op) - dest);
assert(result > 0);
return result;
-
-_failure:
- /* Mark stream as having dirty context, so, it has to be fully reset */
- cctx->dirty = 1;
- return 0;
}
@@ -1422,7 +1417,10 @@ static void LZ4_renormDictT(LZ4_stream_t_internal* LZ4_dict, int nextSize)
}
-int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration)
+int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream,
+ const char* source, char* dest,
+ int inputSize, int maxOutputSize,
+ int acceleration)
{
const tableType_t tableType = byU32;
LZ4_stream_t_internal* streamPtr = &LZ4_stream->internal_donotuse;
diff --git a/lib/lz4.h b/lib/lz4.h
index 23b5ac5..1589be9 100644
--- a/lib/lz4.h
+++ b/lib/lz4.h
@@ -631,11 +631,11 @@ LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") LZ4LIB_API int LZ4
LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") LZ4LIB_API int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize);
/*! LZ4_decompress_fast() : **unsafe!**
- * These functions used to be a bit faster than LZ4_decompress_safe(),
- * but situation has changed in recent versions.
- * Now, `LZ4_decompress_safe()` is as fast and sometimes even faster than `LZ4_decompress_fast()`.
- * Moreover, LZ4_decompress_safe() is protected vs malformed input, while `LZ4_decompress_fast()` is not, making it a security liability.
+ * These functions are generally slightly faster than LZ4_decompress_safe(),
+ * though the difference is small (generally ~5%).
+ * However, the real cost is a risk : LZ4_decompress_safe() is protected vs malformed input, while `LZ4_decompress_fast()` is not, making it a security liability.
* As a consequence, LZ4_decompress_fast() is strongly discouraged, and deprecated.
+ * These functions will generate a deprecation warning in the future.
*
* Last LZ4_decompress_fast() specificity is that it can decompress a block without knowing its compressed size.
* Note that even that functionality could be achieved in a more secure manner if need be,
@@ -648,18 +648,19 @@ LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") LZ4LIB_API int LZ4
* The function expects to finish at block's end exactly.
* If the source stream is detected malformed, the function stops decoding and returns a negative result.
* note : LZ4_decompress_fast*() requires originalSize. Thanks to this information, it never writes past the output buffer.
- * However, since it doesn't know its 'src' size, it may read an unknown amount of input, and overflow input buffer.
- * Also, since match offsets are not validated, match reads from 'src' may underflow.
- * These issues never happen if input data is correct.
+ * However, since it doesn't know its 'src' size, it may read an unknown amount of input, past input buffer bounds.
+ * Also, since match offsets are not validated, match reads from 'src' may underflow too.
+ * These issues never happen if input (compressed) data is correct.
* But they may happen if input data is invalid (error or intentional tampering).
* As a consequence, use these functions in trusted environments with trusted data **only**.
*/
-LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe() instead") LZ4LIB_API
-int LZ4_decompress_fast (const char* src, char* dst, int originalSize);
-LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_continue() instead") LZ4LIB_API
-int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int originalSize);
-LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_usingDict() instead") LZ4LIB_API
-int LZ4_decompress_fast_usingDict (const char* src, char* dst, int originalSize, const char* dictStart, int dictSize);
+
+/* LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe() instead") */
+LZ4LIB_API int LZ4_decompress_fast (const char* src, char* dst, int originalSize);
+/* LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_continue() instead") */
+LZ4LIB_API int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int originalSize);
+/* LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_usingDict() instead") */
+LZ4LIB_API int LZ4_decompress_fast_usingDict (const char* src, char* dst, int originalSize, const char* dictStart, int dictSize);
/*! LZ4_resetStream() :
* An LZ4_stream_t structure must be initialized at least once.