Scala Programming Language
  1. Scala Programming Language
  2. SI-7880

ResizableArray.ensureSize has an infinite loop when the new size is larger than Int.MaxValue/2

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.1, Scala 2.10.2
    • Fix Version/s: Scala 2.11.0-M8
    • Component/s: Collections
    • Labels:
      None
    • Environment:

      scala 2.10.1 compiler and library (but looking at the online source indicates the problem exists in 2.10.2 to).

      Description

      In ensureSize below, when n > Int.MaxValue then newsize: Int may overflow (newsize = newsize * 2) and become negative. Once negative the while loop will never terminate.

      How to reproduce: fill an ArrayBuffer with about 2GB of Bytes.

      protected def ensureSize(n: Int) {
      if (n > array.length)

      { var newsize = array.length * 2 while (n > newsize) newsize = newsize * 2 val newar: Array[AnyRef] = new Array(newsize) scala.compat.Platform.arraycopy(array, 0, newar, 0, size0) array = newar }

      }

        Activity

        Hide
        Simon Ochsenreither added a comment -

        PR: https://github.com/scala/scala/pull/3284

        Feico, could you have a look and confirm that this fixes your issue? Thanks!

        Show
        Simon Ochsenreither added a comment - PR: https://github.com/scala/scala/pull/3284 Feico, could you have a look and confirm that this fixes your issue? Thanks!

          People

          • Assignee:
            Simon Ochsenreither
            Reporter:
            Feico Dillema
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development