Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8245038

BigInteger.squareToLen(x, len, z) may compute incorrect results when called reflectively

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • tbd
    • 15
    • core-libs
    • None
    • generic
    • generic

      The BigInteger method

      private static final int[] squareToLen(int[] x, int len, int[] z)

      may compute incorrect results when invoked via reflection and z.length > 2 * len. For example:

      x = {1, 2}
      len = 2
      with z.length = 4: {0, 1, 4, 4} (as expected)
      with z.length = 5: {0, 1, 0, 8, 0} instead of {0, 1, 4, 4, 0}

      The core issue is in implMulAdd(), where 'offset' is set to
      "out.length-offset - 1"
      instead of
      "zlen - offset - 1"
      (which requires to add zlen as argument).

      Calling a private method as such is not guaranteed to work, but if there is an error, it should probably be fixed.

            bpb Brian Burkhalter
            bpb Brian Burkhalter
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: