Skip to content

Commit

Permalink
[new] Re-enable Snappy compressor
Browse files Browse the repository at this point in the history
Upstream safety issue has been resolved,
Ref. <airlift/aircompressor#183>.
  • Loading branch information
ptaoussanis committed Feb 26, 2024
1 parent 7be9b4f commit cb0b871
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/taoensso/nippy.clj
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@
compression/lz4-compressor
compression/lz4hc-compressor
#_compression/lzo-compressor
#_compression/snappy-compressor ; Can be unsafe
compression/snappy-compressor
compression/lzma2-compressor

encryption/encrypt
Expand Down
15 changes: 9 additions & 6 deletions src/taoensso/nippy/compression.clj
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,16 @@
See `taoensso.nippy-benchmarks` for detailed comparative benchmarks."
(LZMA2Compressor. 0))

(enc/def* snappy-compressor
"Default `Snappy` compressor:
- Compression ratio: `C` (0.58 on reference benchmark).
- Compression speed: `A+` (206 msecs on reference benchmark).
- Decompression speed: `B` (134 msecs on reference benchmark).
Good general-purpose compressor, favours speed.
See `taoensso.nippy-benchmarks` for detailed comparative benchmarks."
(SnappyCompressor. false))

(enc/def* ^:no-doc lz4hc-compressor
"Different LZ4 modes no longer supported, prefer `lz4-compressor`."
{:deprecated "v3.4.0-RC1 (2024-02-06)"}
(LZ4Compressor.))

(enc/def* ^:no-doc snappy-compressor
"Snappy compressor no longer recommended, prefer `lz4-compressor`.
Decompression can be unsafe against untrusted data!"
{:deprecated "v3.4.0-RC1 (2024-02-06)"}
(SnappyCompressor. false))
15 changes: 10 additions & 5 deletions test/taoensso/nippy_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,21 @@
;;;; Compressors

(deftest _compressors
(println "\nTesting decompression of random data...")
(doseq [c [compr/zstd-compressor
compr/lz4-compressor
compr/lzo-compressor
#_compr/snappy-compressor ; Ref. <https://github.com/airlift/aircompressor/issues/183>
compr/snappy-compressor
compr/lzma2-compressor]]

(dotimes [_ 2e4]
(is
(nil? (enc/catching (compr/decompress c (crypto/rand-bytes 1024))))
"Decompression never crashes JVM, even against invalid data"))))
(print (str " With " (name (compr/header-id c)))) (flush)
(dotimes [_ 5] ; Slow, a few k laps should be sufficient for CI
(print ".") (flush)
(dotimes [_ 1000]
(is
(nil? (enc/catching (compr/decompress c (crypto/rand-bytes 1024))))
"Decompression never crashes JVM, even against invalid data")))
(println)))

;;;; Benchmarks

Expand Down

0 comments on commit cb0b871

Please sign in to comment.