Sophie

Sophie

distrib > Mageia > 8 > i586 > by-pkgid > c10308044d5c491bdcab79f420a50e93 > files > 3

erlang-snappy-1.1.1-0.19.git348da43.mga8.src.rpm

From: Peter Membrey <peter@membrey.hk>
Date: Fri, 16 May 2014 21:32:53 +0800
Subject: [PATCH] Added a check for empty IOLists during decompression. It will
 create a new clean empty binary, was not sure it would be save to re-use the
 original.


diff --git a/c_src/snappy_nif.cc b/c_src/snappy_nif.cc
index b22f743..1a80815 100644
--- a/c_src/snappy_nif.cc
+++ b/c_src/snappy_nif.cc
@@ -167,6 +167,14 @@ snappy_decompress_erl(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
         return enif_make_badarg(env);
     }
 
+    // Check that the binary is not empty
+    if(bin.size == 0) {
+        // Snappy library cannot decompress an empty binary - although
+        // it will unfortunately let you compress one. If an empty binary
+        // has been passed - send an empty binary back.
+        return make_ok(env, enif_make_binary(env,&ret));
+    }
+
     try {
         if(!snappy::GetUncompressedLength(SC_PTR(bin.data), bin.size, &len)) {
             return make_error(env, "data_not_compressed");