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

Constructor BigInteger(String val, int radix) doesn't detect overflow

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • 8
    • core-libs
    • b115
    • linux_ubuntu
    • Verified

      FULL PRODUCT VERSION :
      java version " 1.8.0-ea "
      Java(TM) SE Runtime Environment (build 1.8.0-ea-b99)
      Java HotSpot(TM) 64-Bit Server VM (build 25.0-b41, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux kisa 3.8.0-26-generic #38-Ubuntu SMP Mon Jun 17 21:43:33 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Constructors BigInteger(String val, int radix) and BigInteger(String val) doesn't detect that value of val is out of supported range. They may consume long string silently and construct BigInteger object with incorrect value.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run and compile the attached test

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Constructor throws ArithmeticException
      ACTUAL -
      bi=1


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.math.BigInteger;

      public class BigIntegerStringConstructorTest {
          
          public static void main(String[] args) {
              StringBuilder sb = new StringBuilder();
              sb.append('1');
              for (int i = 0; i < (1 << 30) - 1; i++) {
                  sb.append('0');
              }
              sb.append('1');
              String s = sb.toString();
              sb = null;
              BigInteger bi = new BigInteger(s, 16);
              System.out.println( " bi= " + bi);
          }
      }

      ---------- END SOURCE ----------

            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: