Skip to content

Commit

Permalink
Fix stack overflow issue when using t/into
Browse files Browse the repository at this point in the history
t/into used concat in a way that would cause stack overflows with large
numbers of chunks.
  • Loading branch information
leon-barrett committed Sep 7, 2016
1 parent 4d5f285 commit bbbda62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/tesser/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions core/test/tesser/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit bbbda62

Please sign in to comment.