From 53714cc192a0873352b40e0256179ef6e7a48aeb Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Fri, 29 May 2015 14:13:35 +0700 Subject: [PATCH 1/4] More robust record deserialization --- src/taoensso/nippy.clj | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index e825440..57c13df 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -461,6 +461,7 @@ (encore/repeatedly-into* ~coll (quot (.readInt in#) 2) [(thaw-from-in in#) (thaw-from-in in#)]))) +(def ^:private class-method-sig (into-array Class [IPersistentMap])) (declare ^:private custom-readers) (defn- read-custom! [type-id in] @@ -553,10 +554,17 @@ (bigint (read-biginteger in))) id-record - (let [class ^Class (Class/forName (read-utf8 in)) - meth-sig (into-array Class [IPersistentMap]) - method ^Method (.getMethod class "create" meth-sig)] - (.invoke method class (into-array Object [(thaw-from-in in)]))) + (let [class-name (read-utf8 in) + content (thaw-from-in in)] + (try + (let [class (Class/forName class-name) + method (.getMethod class "create" class-method-sig)] + (.invoke method class (into-array Object [content]))) + (catch Exception e + {:nippy/unthawable class-name + :type :record + :content content + :throwable e}))) id-date (Date. (.readLong in)) id-uuid (UUID. (.readLong in) (.readLong in)) From 2b19f8eab50a93e2470e7cfd7b7561a9b63124e3 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Fri, 29 May 2015 14:20:14 +0700 Subject: [PATCH 2/4] Refactor reading of possibly-unthawable types --- src/taoensso/nippy.clj | 56 +++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index 57c13df..c0f01ec 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -490,21 +490,40 @@ id-reader (let [edn (read-utf8 in)] - (try (edn/read-string {:readers *data-readers*} edn) - (catch Exception e {:nippy/unthawable edn - :type :reader - :throwable e}))) + (try + (edn/read-string {:readers *data-readers*} edn) + (catch Exception e + {:type :reader + :throwable e + :nippy/unthawable edn}))) id-serializable (let [class-name (read-utf8 in)] - (try (let [;; .readObject _before_ Class/forName: it'll always read - ;; all data before throwing - object (.readObject (ObjectInputStream. in)) - ^Class class (Class/forName class-name)] - (cast class object)) - (catch Exception e {:nippy/unthawable class-name - :type :serializable - :throwable e}))) + (try + (let [content (.readObject (ObjectInputStream. in))] + (try + (let [class (Class/forName class-name)] + (cast class content)) + (catch Exception e + {:type :serializable + :throwable e + :nippy/unthawable {:class-name class-name :content content}}))) + (catch Exception e + {:type :serializable + :throwable e + :nippy/unthawable {:class-name class-name :content nil}}))) + + id-record + (let [class-name (read-utf8 in) + content (thaw-from-in in)] + (try + (let [class (Class/forName class-name) + method (.getMethod class "create" class-method-sig)] + (.invoke method class (into-array Object [content]))) + (catch Exception e + {:type :record + :throwable e + :nippy/unthawable {:class-name class-name :content content}}))) id-bytes (read-bytes in) id-nil nil @@ -553,19 +572,6 @@ id-ratio (/ (bigint (read-biginteger in)) (bigint (read-biginteger in))) - id-record - (let [class-name (read-utf8 in) - content (thaw-from-in in)] - (try - (let [class (Class/forName class-name) - method (.getMethod class "create" class-method-sig)] - (.invoke method class (into-array Object [content]))) - (catch Exception e - {:nippy/unthawable class-name - :type :record - :content content - :throwable e}))) - id-date (Date. (.readLong in)) id-uuid (UUID. (.readLong in) (.readLong in)) From fc2b216e6e38a7fc429bdb9b360ccf8b18b1fd9c Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Fri, 29 May 2015 14:21:59 +0700 Subject: [PATCH 3/4] Bump encore dep (v1.32.0) --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 78e5096..d650b12 100644 --- a/project.clj +++ b/project.clj @@ -14,7 +14,7 @@ :dependencies [[org.clojure/clojure "1.4.0"] [org.clojure/tools.reader "0.9.2"] - [com.taoensso/encore "1.28.0"] + [com.taoensso/encore "1.32.0"] [org.iq80.snappy/snappy "0.3"] [org.tukaani/xz "1.5"] [net.jpountz.lz4/lz4 "1.3"]] From 5406bfa970e963376e46b9216f2f2e3024f28c46 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Fri, 29 May 2015 14:25:33 +0700 Subject: [PATCH 4/4] v2.9.0-RC3 --- CHANGELOG.md | 11 +++++++++++ README.md | 2 +- project.clj | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91a8a09..c68b9c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ > This project uses [Break Versioning](https://github.com/ptaoussanis/encore/blob/master/BREAK-VERSIONING.md) as of **Aug 16, 2014**. +## v2.9.0-RC3 / 2015 May 29 + +> This is a non-breaking **stability release** + +* **Implementation**: more robust error handling for unthawable records + +```clojure +[com.taoensso/nippy "2.9.0-RC3"] +``` + + ## v2.9.0-RC2 / 2015 May 6 > This is a non-breaking **performance release** diff --git a/README.md b/README.md index 12ef1dd..686c5f2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ```clojure [com.taoensso/nippy "2.8.0"] ; Stable -[com.taoensso/nippy "2.9.0-RC2"] ; Dev, please see CHANGELOG for details +[com.taoensso/nippy "2.9.0-RC3"] ; Dev, please see CHANGELOG for details ``` # Nippy, a Clojure serialization library diff --git a/project.clj b/project.clj index d650b12..9b3ec96 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject com.taoensso/nippy "2.9.0-RC2" +(defproject com.taoensso/nippy "2.9.0-RC3" :author "Peter Taoussanis " :description "Clojure serialization library" :url "https://github.com/ptaoussanis/nippy"