Skip to content

Commit

Permalink
Merge pull request #4224 from liqunl/getChars
Browse files Browse the repository at this point in the history
Add missing checks on data array for getChars
  • Loading branch information
DanHeidinga authored Jan 17, 2019
2 parents 8eb6f83 + 63f1998 commit 6b6c2c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions jcl/src/java.base/share/classes/java/lang/String.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar18-SE]*/
/*******************************************************************************
* Copyright (c) 1998, 2018 IBM Corp. and others
* Copyright (c) 1998, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -1830,7 +1830,7 @@ public byte[] getBytes(String encoding) throws UnsupportedEncodingException {
* when buffer is null
*/
public void getChars(int start, int end, char[] data, int index) {
if (0 <= start && start <= end && end <= lengthInternal()) {
if (0 <= start && start <= end && end <= lengthInternal() && 0 <= index && ((end - start) <= (data.length - index))) {
getCharsNoBoundChecks(start, end, data, index);
} else {
throw new StringIndexOutOfBoundsException();
Expand All @@ -1849,7 +1849,7 @@ void getCharsNoBoundChecks(int start, int end, char[] data, int index) {
}

void getChars(int start, int end, byte[] data, int index) {
if (0 <= start && start <= end && end <= lengthInternal()) {
if (0 <= start && start <= end && end <= lengthInternal() && 0 <= index && ((end - start) <= ((data.length / 2) - index))) {
getCharsNoBoundChecks(start, end, data, index);
} else {
throw new StringIndexOutOfBoundsException();
Expand Down Expand Up @@ -5906,7 +5906,7 @@ public byte[] getBytes(String encoding) throws UnsupportedEncodingException {
* when buffer is null
*/
public void getChars(int start, int end, char[] data, int index) {
if (0 <= start && start <= end && end <= lengthInternal()) {
if (0 <= start && start <= end && end <= lengthInternal() && 0 <= index && ((end - start) <= (data.length - index))) {
if (enableCompression && (null == compressionFlag || count >= 0)) {
decompress(value, start, data, index, end - start);
} else {
Expand Down
4 changes: 2 additions & 2 deletions jcl/src/java.base/share/classes/java/lang/StringBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package java.lang;

/*******************************************************************************
* Copyright (c) 1998, 2018 IBM Corp. and others
* Copyright (c) 1998, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -1384,7 +1384,7 @@ public synchronized StringBuffer replace(int start, int end, String string) {
capacity = capacity & ~sharedBit;
}

string.getChars(0, size, value, start);
string.getCharsNoBoundChecks(0, size, value, start);

count = currentLength - difference;

Expand Down

0 comments on commit 6b6c2c8

Please sign in to comment.