Skip to content

Commit 25e8f4e

Browse files
committed
CLJ-2916 LazySeq - realize before serializing and do not serialize IFn
1 parent d433ceb commit 25e8f4e

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/jvm/clojure/lang/LazySeq.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
public final class LazySeq extends Obj implements ISeq, Sequential, List, IPending, IHashEq{
2222

23-
private static final long serialVersionUID = -7345643944998411680L;
23+
private static final long serialVersionUID = -7531333024710395876L;
2424

25-
private IFn fn;
25+
private transient IFn fn;
2626
private Object sv;
2727
private ISeq s;
2828
private Lock lock;
@@ -300,5 +300,15 @@ public boolean isRealized(){
300300
}
301301
return true;
302302
}
303+
304+
// custom Serializable implementation - ensure seq is fully-realized before writing
305+
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
306+
ISeq s = this;
307+
while(s != null) {
308+
s = s.next();
309+
}
310+
out.defaultWriteObject();
311+
}
312+
303313
}
304314

test/clojure/test_clojure/serialization.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
; lazy seqs
9393
(lazy-seq nil)
9494
(lazy-seq (list* (range 50)))
95+
(iterator-seq (.iterator (range 50)))
9596

9697
; transient / persistent! round-trip
9798
(build-via-transient [])
@@ -182,8 +183,7 @@
182183
(agent nil)
183184

184185
;; stateful seqs
185-
(enumeration-seq (java.util.Collections/enumeration (range 50)))
186-
(iterator-seq (.iterator (range 50)))))
186+
(enumeration-seq (java.util.Collections/enumeration (range 50)))))
187187

188188
;; necessary for CVE-2024-22871
189189
(deftest CLJ-2839

0 commit comments

Comments
 (0)