couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject [2/3] couch commit: updated refs/heads/master to aef448d
Date Tue, 03 May 2016 19:05:35 GMT
Raise an exception on corrupt binary decompression


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/925c1deb
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/925c1deb
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/925c1deb

Branch: refs/heads/master
Commit: 925c1deb738617cd48bab40707b9b60e32a4dcdd
Parents: 21b2847
Author: Eric Avdey <eiri@eiri.ca>
Authored: Tue May 3 14:58:51 2016 -0300
Committer: Eric Avdey <eiri@eiri.ca>
Committed: Tue May 3 14:58:51 2016 -0300

----------------------------------------------------------------------
 src/couch_compress.erl        |  8 ++++++--
 test/couch_compress_tests.erl | 12 ++++++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/925c1deb/src/couch_compress.erl
----------------------------------------------------------------------
diff --git a/src/couch_compress.erl b/src/couch_compress.erl
index f9b5aa6..71588b2 100644
--- a/src/couch_compress.erl
+++ b/src/couch_compress.erl
@@ -65,7 +65,9 @@ decompress(<<?SNAPPY_PREFIX, Rest/binary>>) ->
     {ok, TermBin} = snappy:decompress(Rest),
     binary_to_term(TermBin);
 decompress(<<?TERM_PREFIX, _/binary>> = Bin) ->
-    binary_to_term(Bin).
+    binary_to_term(Bin);
+decompress(_) ->
+    error(invalid_compression).
 
 
 is_compressed(<<?SNAPPY_PREFIX, _/binary>>, Method) ->
@@ -77,5 +79,7 @@ is_compressed(<<?COMPRESSED_TERM_PREFIX, _/binary>>, _Method)
->
 is_compressed(<<?TERM_PREFIX, _/binary>>, Method) ->
     Method =:= none;
 is_compressed(Term, _Method) when not is_binary(Term) ->
-    false.
+    false;
+is_compressed(_, _) ->
+    error(invalid_compression).
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/925c1deb/test/couch_compress_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_compress_tests.erl b/test/couch_compress_tests.erl
index f47bf47..6d6e6a7 100644
--- a/test/couch_compress_tests.erl
+++ b/test/couch_compress_tests.erl
@@ -25,6 +25,7 @@
 -define(SNAPPY, <<1,49,64,131,104,1,108,0,0,0,5,104,2,100,0,
     1,97,97,1,104,1,8,8,98,97,2,5,8,8,99,97,3,5,8,44,100,97,
     4,104,2,100,0,1,101,97,5,106>>).
+-define(CORRUPT, <<2,12,85,06>>).
 
 
 compress_test_() ->
@@ -38,7 +39,8 @@ decompress_test_() ->
     [
         ?_assertEqual(?TERM, couch_compress:decompress(?NONE)),
         ?_assertEqual(?TERM, couch_compress:decompress(?DEFLATE)),
-        ?_assertEqual(?TERM, couch_compress:decompress(?SNAPPY))
+        ?_assertEqual(?TERM, couch_compress:decompress(?SNAPPY)),
+        ?_assertError(invalid_compression, couch_compress:decompress(?CORRUPT))
     ].
 
 recompress_test_() ->
@@ -62,5 +64,11 @@ is_compressed_test_() ->
         ?_assertNot(couch_compress:is_compressed(?DEFLATE, none)),
         ?_assertNot(couch_compress:is_compressed(?DEFLATE, snappy)),
         ?_assertNot(couch_compress:is_compressed(?SNAPPY, none)),
-        ?_assertNot(couch_compress:is_compressed(?SNAPPY, {deflate, 9}))
+        ?_assertNot(couch_compress:is_compressed(?SNAPPY, {deflate, 9})),
+        ?_assertError(invalid_compression,
+            couch_compress:is_compressed(?CORRUPT, none)),
+        ?_assertError(invalid_compression,
+            couch_compress:is_compressed(?CORRUPT, {deflate, 9})),
+        ?_assertError(invalid_compression,
+            couch_compress:is_compressed(?CORRUPT, snappy))
     ].


Mime
View raw message