summaryrefslogtreecommitdiffstats
path: root/lz4.h
diff options
context:
space:
mode:
authoryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2011-06-04 17:15:43 (GMT)
committeryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2011-06-04 17:15:43 (GMT)
commit6b798d5e40e4c0788f7c51f6e9b0e9c4e966d068 (patch)
treef21ae23e1e95dffeee7f5b47c37dc93656ce26a3 /lz4.h
parent0121f47e00e44a40a41d7b49852129b12f5e1d43 (diff)
downloadlz4-6b798d5e40e4c0788f7c51f6e9b0e9c4e966d068.zip
lz4-6b798d5e40e4c0788f7c51f6e9b0e9c4e966d068.tar.gz
lz4-6b798d5e40e4c0788f7c51f6e9b0e9c4e966d068.tar.bz2
New function : LZ4_uncompress : secure version which is safe against buffer overflow attacks
New function : LZ4_uncompress_unknownOutputSize : secure but slower version which also guess the size of data to be decoded The demo file compression program (main.c) is updated to use these new functions LZ4_decode is still supported but in deprecated status, due to its vulnerability to malicious buffer overflow scenario git-svn-id: https://lz4.googlecode.com/svn/trunk@9 650e7d94-2a16-8b24-b05c-7c0b3f6821cd
Diffstat (limited to 'lz4.h')
-rw-r--r--lz4.h57
1 files changed, 39 insertions, 18 deletions
diff --git a/lz4.h b/lz4.h
index b932b39..031e8ee 100644
--- a/lz4.h
+++ b/lz4.h
@@ -34,21 +34,11 @@ extern "C" {
//****************************
-// Instructions
-//****************************
-
-// Uncomment next line to ensure that LZ4_Decode will never write in destination buffer more than "decompressedSize" bytes
-// If commented, the decoder may write up to 3 bytes more than decompressedSize, so provide extra room in dest buffer for that
-// Recommendation : keep commented, for improved performance; ensure that destination buffer is at least decompressedSize + 3 Bytes
-// #define SAFEWRITEBUFFER
-
-
-//****************************
// Simple Functions
//****************************
-int LZ4_compress (char* source, char* dest, int isize);
-int LZ4_decode (char* source, char* dest, int isize);
+int LZ4_compress (char* source, char* dest, int isize);
+int LZ4_uncompress (char* source, char* dest, int osize);
/*
LZ4_compress :
@@ -57,12 +47,12 @@ LZ4_compress :
To avoid any problem, size it to handle worst cases situations (input data not compressible)
Worst case size is : "inputsize + 0.4%", with "0.4%" being at least 8 bytes.
-LZ4_decode :
- return : the number of bytes in decoded buffer dest
- note 1 : isize is the input size, therefore the compressed size
- note 2 : destination buffer must be already allocated.
- The program calling the decoder must know in advance the size of decoded stream to properly allocate the destination buffer
- Note that, in fast mode, the destination buffer size must be at least "decompressedSize + 3 Bytes"
+LZ4_uncompress :
+ return : the number of bytes read in the source buffer
+ If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction
+ This version never writes beyond dest + osize, and is therefore protected against malicious data packets
+ note 1 : osize is the output size, therefore the original size
+ note 2 : destination buffer must be already allocated
*/
@@ -70,6 +60,19 @@ LZ4_decode :
// Advanced Functions
//****************************
+int LZ4_uncompress_unknownOutputSize (char* source, char* dest, int isize, int maxOutputSize);
+
+/*
+LZ4_uncompress :
+ return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
+ If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction
+ This version never writes beyond dest + osize, and is therefore protected against malicious data packets
+ note 1 : isize is the input size, therefore the compressed size
+ note 2 : destination buffer must be already allocated
+ note 3 : this version is slower by up to 10%, and is therefore not recommended for general use
+*/
+
+
int LZ4_compressCtx(void** ctx, char* source, char* dest, int isize);
/*
@@ -85,6 +88,24 @@ LZ4_compressCtx :
*/
+//****************************
+// Deprecated Functions
+//****************************
+
+int LZ4_decode (char* source, char* dest, int isize);
+
+/*
+LZ4_decode :
+ return : the number of bytes in decoded buffer dest
+ note 1 : isize is the input size, therefore the compressed size
+ note 2 : destination buffer must be already allocated.
+ The program calling the decoder must know in advance the size of decoded stream to properly allocate the destination buffer
+ The destination buffer size must be at least "decompressedSize + 3 Bytes"
+ This version is unprotected against malicious data packets designed to create buffer overflow errors.
+ It is therefore deprecated, but still present in this version for compatibility.
+*/
+
+
#if defined (__cplusplus)
}
#endif