8155608: String intrinsic range checks are not strict enough

Range checks in inflate, compress and getChars are not strict enough.

Reviewed-by: kvn, twisti, jrose
This commit is contained in:
Tobias Hartmann 2016-05-13 08:31:23 +02:00
parent bcec429910
commit dd051e31bb
2 changed files with 7 additions and 5 deletions

View File

@ -557,7 +557,7 @@ final class StringLatin1 {
// inflatedCopy byte[] -> char[]
@HotSpotIntrinsicCandidate
private static void inflate(byte[] src, int srcOff, char[] dst, int dstOff, int len) {
public static void inflate(byte[] src, int srcOff, char[] dst, int dstOff, int len) {
for (int i = 0; i < len; i++) {
dst[dstOff++] = (char)(src[srcOff++] & 0xff);
}
@ -567,7 +567,7 @@ final class StringLatin1 {
@HotSpotIntrinsicCandidate
public static void inflate(byte[] src, int srcOff, byte[] dst, int dstOff, int len) {
// We need a range check here because 'putChar' has no checks
checkBoundsOffCount(dstOff, len, dst.length);
checkBoundsOffCount(dstOff << 1, len << 1, dst.length);
for (int i = 0; i < len; i++) {
StringUTF16.putChar(dst, dstOff++, src[srcOff++] & 0xff);
}

View File

@ -144,7 +144,7 @@ final class StringUTF16 {
// compressedCopy char[] -> byte[]
@HotSpotIntrinsicCandidate
private static int compress(char[] src, int srcOff, byte[] dst, int dstOff, int len) {
public static int compress(char[] src, int srcOff, byte[] dst, int dstOff, int len) {
for (int i = 0; i < len; i++) {
char c = src[srcOff];
if (c > 0xFF) {
@ -162,7 +162,7 @@ final class StringUTF16 {
@HotSpotIntrinsicCandidate
public static int compress(byte[] src, int srcOff, byte[] dst, int dstOff, int len) {
// We need a range check here because 'getChar' has no checks
checkBoundsOffCount(srcOff, len, src.length);
checkBoundsOffCount(srcOff << 1, len << 1, src.length);
for (int i = 0; i < len; i++) {
char c = getChar(src, srcOff);
if (c > 0xFF) {
@ -211,7 +211,9 @@ final class StringUTF16 {
@HotSpotIntrinsicCandidate
public static void getChars(byte[] value, int srcBegin, int srcEnd, char dst[], int dstBegin) {
// We need a range check here because 'getChar' has no checks
checkBoundsOffCount(srcBegin, srcEnd - srcBegin, value.length);
if (srcBegin < srcEnd) {
checkBoundsOffCount(srcBegin << 1, (srcEnd - srcBegin) << 1, value.length);
}
for (int i = srcBegin; i < srcEnd; i++) {
dst[dstBegin++] = getChar(value, i);
}