From 26c01c799afab3e3e89daea6bddff37acb560b90 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Thu, 27 Nov 2014 16:53:16 +0700 Subject: [PATCH] Add option to disable v1 thaw compatibility --- src/taoensso/nippy.clj | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index 707224d..74621fe 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -565,10 +565,13 @@ Options include: :compressor - An ICompressor, :auto (requires Nippy header), or nil. :encryptor - An IEncryptor, :auto (requires Nippy header), or nil." - [^bytes ba & [{:keys [compressor encryptor password] - :or {compressor :auto - encryptor :auto} - :as opts}]] + [^bytes ba + & [{:keys [compressor encryptor password v1-compatibility?] + :or {compressor :auto + encryptor :auto + v1-compatibility? true ; Recommend disabling when possible + } + :as opts}]] (assert (not (contains? opts :headerless-meta)) ":headerless-meta `thaw` option removed as of Nippy v2.7.") @@ -598,11 +601,15 @@ (catch Exception e (ex "Decryption/decompression failure, or data unfrozen/damaged."))))) - thaw-nippy-v1-data ; A little hackish, but necessary + ;; This is hackish and can actually currently result in JVM core dumps + ;; due to buggy Snappy behaviour, Ref. http://goo.gl/mh7Rpy. + thaw-nippy-v1-data (fn [data-ba] - (try (thaw-data data-ba :snappy nil) - (catch Exception _ - (thaw-data data-ba nil nil))))] + (if-not v1-compatibility? + (throw (Exception. "v1 compatibility disabled")) + (try (thaw-data data-ba :snappy nil) + (catch Exception _ + (thaw-data data-ba nil nil)))))] (if-let [[data-ba {:keys [compressor-id encryptor-id unrecognized-meta?] :as head-meta}] (try-parse-header ba)]