This is an automated email from the ASF dual-hosted git repository.

adar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 8166dd7  [compression] Use new lz4 API
8166dd7 is described below

commit 8166dd7100b99e3ea5d6ae3502b4f43c4ecd560e
Author: lingbin <[email protected]>
AuthorDate: Wed Oct 30 21:23:18 2019 +0800

    [compression] Use new lz4 API
    
    In the new version (v1.9.1) of lz4, `LZ4_decompress_fast()` is deprecated
    and unsafe. It is recommended to use `LZ4_decompress_safe()`
    
    The documentation in lz4.h is as follows:
    
    /*! LZ4_decompress_fast() : **unsafe!**
     *  These functions used to be faster than LZ4_decompress_safe(),
     *  but it has changed, and they are now slower than LZ4_decompress_safe().
     *  This is because LZ4_decompress_fast() doesn't know the input size,
     *  and therefore must progress more cautiously in the input buffer to not 
read beyond the end of
        block.
     *  On top of that `LZ4_decompress_fast()` is not protected vs malformed or 
malicious inputs,
        making it a security liability.
     *  As a consequence, LZ4_decompress_fast() is strongly discouraged, and 
deprecated.
     */
    
    Change-Id: Ib343fda7fff1d14ee7bc551be3ac87b068504359
    Reviewed-on: http://gerrit.cloudera.org:8080/14587
    Tested-by: Kudu Jenkins
    Reviewed-by: Adar Dembo <[email protected]>
---
 src/kudu/util/compression/compression_codec.cc | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/kudu/util/compression/compression_codec.cc 
b/src/kudu/util/compression/compression_codec.cc
index a2231b6..b927d48 100644
--- a/src/kudu/util/compression/compression_codec.cc
+++ b/src/kudu/util/compression/compression_codec.cc
@@ -134,7 +134,7 @@ class SnappyCodec : public CompressionCodec {
 
   Status Uncompress(const Slice& compressed,
                     uint8_t *uncompressed,
-                    size_t uncompressed_length) const OVERRIDE {
+                    size_t /*uncompressed_length*/) const OVERRIDE {
     bool success = snappy::RawUncompress(reinterpret_cast<const char 
*>(compressed.data()),
                                          compressed.size(), 
reinterpret_cast<char *>(uncompressed));
     return success ? Status::OK() : Status::Corruption("unable to uncompress 
the buffer");
@@ -157,9 +157,9 @@ class Lz4Codec : public CompressionCodec {
 
   Status Compress(const Slice& input,
                   uint8_t *compressed, size_t *compressed_length) const 
OVERRIDE {
-    int n = LZ4_compress(reinterpret_cast<const char *>(input.data()),
-                         reinterpret_cast<char *>(compressed), input.size());
-    *compressed_length = n;
+    *compressed_length = LZ4_compress(reinterpret_cast<const char 
*>(input.data()),
+                                      reinterpret_cast<char *>(compressed),
+                                      input.size());
     return Status::OK();
   }
 
@@ -178,9 +178,10 @@ class Lz4Codec : public CompressionCodec {
   Status Uncompress(const Slice& compressed,
                     uint8_t *uncompressed,
                     size_t uncompressed_length) const OVERRIDE {
-    int n = LZ4_decompress_fast(reinterpret_cast<const char 
*>(compressed.data()),
-                                reinterpret_cast<char *>(uncompressed), 
uncompressed_length);
-    if (n != compressed.size()) {
+    int n = LZ4_decompress_safe(reinterpret_cast<const char 
*>(compressed.data()),
+                                reinterpret_cast<char *>(uncompressed),
+                                compressed.size(), uncompressed_length);
+    if (n != uncompressed_length) {
       return Status::Corruption(
         StringPrintf("unable to uncompress the buffer. error near %d, buffer", 
-n),
                      KUDU_REDACT(compressed.ToDebugString(100)));

Reply via email to