Description
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 ----------
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 ----------
Attachments
Issue Links
- relates to
-
JDK-8027595 Enable BigInteger overflow tests in JTREG
- Closed
-
JDK-6910473 java.math.BigInteger.bitLength() may return negative "int" on large numbers
- Closed