--- a/src/java.base/share/classes/java/math/BigDecimal.java Tue Jan 15 16:40:31 2019 -0500
+++ b/src/java.base/share/classes/java/math/BigDecimal.java Tue Jan 15 22:54:09 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,7 @@
import static java.math.BigInteger.LONG_MASK;
import java.util.Arrays;
+import java.util.Objects;
/**
* Immutable, arbitrary-precision signed decimal numbers. A
@@ -424,9 +425,14 @@
* @since 1.5
*/
public BigDecimal(char[] in, int offset, int len, MathContext mc) {
- // protect against huge length.
- if (offset + len > in.length || offset < 0)
- throw new NumberFormatException("Bad offset or len arguments for char[] input.");
+ // protect against huge length, negative values, and integer overflow
+ try {
+ Objects.checkFromIndexSize(offset, len, in.length);
+ } catch (IndexOutOfBoundsException e) {
+ throw new NumberFormatException
+ ("Bad offset or len arguments for char[] input.");
+ }
+
// This is the primary string to BigDecimal constructor; all
// incoming strings end up here; it uses explicit (inline)
// parsing for speed and generates at most one intermediate