From bbbda625bd37504297a103c034c0e1a441f5b0d5 Mon Sep 17 00:00:00 2001 From: Leon Barrett Date: Wed, 7 Sep 2016 16:50:01 -0700 Subject: [PATCH] Fix stack overflow issue when using t/into t/into used concat in a way that would cause stack overflows with large numbers of chunks. --- core/src/tesser/core.clj | 4 ++-- core/test/tesser/core_test.clj | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/tesser/core.clj b/core/src/tesser/core.clj index 278ed54..f40a163 100644 --- a/core/src/tesser/core.clj +++ b/core/src/tesser/core.clj @@ -743,8 +743,8 @@ :reducer conj :post-reducer identity :combiner-identity vector - :combiner core/concat - :post-combiner (partial core/into coll)}) + :combiner conj + :post-combiner #(core/into coll (apply concat %))}) (defwraptransform post-combine "Transforms the output of a fold by applying a function to it. diff --git a/core/test/tesser/core_test.clj b/core/test/tesser/core_test.clj index 0643d15..a56d163 100644 --- a/core/test/tesser/core_test.clj +++ b/core/test/tesser/core_test.clj @@ -190,6 +190,16 @@ (is (= (sort (t/tesser chunks (t/into []))) (sort (flatten1 chunks)))))) +(deftest into-vec-stack-overflow-regression + (testing (str "t/into used to have a stack overflow bug for large numbers " + "of chunks because of concat usage like described here: " + "https://stuartsierra.com/2015/04/26/clojure-donts-concat") + (let [n 100000] + (is (= (set (range n)) + (->> (t/into []) + (t/tesser (map vector (range n))) + set)))))) + (defspec into-set-spec test-opts (prop/for-all [chunks (chunks gen/int)]