Skip to content

Commit e4ea3ab

Browse files
authored
Fix CVE-2022-36944 for LazyList
Backport fix for CVE-2022-36944 from 2.13. Code copy-pasted in a browser.
1 parent 06526ea commit e4ea3ab

File tree

1 file changed

+7
-4
lines changed
  • compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable

1 file changed

+7
-4
lines changed

compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/LazyList.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import scala.collection.generic.{
3333
SeqFactory
3434
}
3535
import scala.collection.immutable.{LinearSeq, NumericRange}
36-
import scala.collection.mutable.{ArrayBuffer, Builder, StringBuilder}
36+
import scala.collection.mutable.{Builder, StringBuilder}
3737
import scala.language.implicitConversions
3838

3939
/** This class implements an immutable linked list that evaluates elements
@@ -1512,14 +1512,17 @@ object LazyList extends SeqFactory[LazyList] {
15121512

15131513
private[this] def readObject(in: ObjectInputStream): Unit = {
15141514
in.defaultReadObject()
1515-
val init = new ArrayBuffer[A]
1515+
val init = new mutable.ListBuffer[A]
15161516
var initRead = false
15171517
while (!initRead) in.readObject match {
15181518
case SerializeEnd => initRead = true
1519-
case a => init += a.asInstanceOf[A]
1519+
case a => init += a.asInstanceOf[A]
15201520
}
15211521
val tail = in.readObject().asInstanceOf[LazyList[A]]
1522-
coll = tail.prependedAllToLL(init)
1522+
// scala/scala#10118: caution that no code path can evaluate `tail.state`
1523+
// before the resulting LazyList is returned
1524+
val it = init.toList.iterator
1525+
coll = newLL(stateFromIteratorConcatSuffix(it)(tail.state))
15231526
}
15241527

15251528
private[this] def readResolve(): Any = coll

0 commit comments

Comments
 (0)