6993561: java.awt.image.SampleModel.setSamples() methods not always throw ArrayIndexOutOfBoundsException

Reviewed-by: jgodinez, prr
This commit is contained in:
Andrew Brygin 2011-03-22 11:22:38 +03:00
parent 4e70e79c7f
commit 91f8f158a4
2 changed files with 36 additions and 9 deletions

View File

@ -1315,9 +1315,16 @@ public abstract class SampleModel
int iArray[], DataBuffer data) {
int Offset=0;
int x1 = x + w;
int y1 = y + h;
if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
{
throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
}
for (int i=y; i<(y+h); i++) {
for (int j=x; j<(x+w); j++) {
for (int i=y; i<y1; i++) {
for (int j=x; j<x1; j++) {
setSample(j, i, b, iArray[Offset++], data);
}
}
@ -1345,9 +1352,17 @@ public abstract class SampleModel
public void setSamples(int x, int y, int w, int h, int b,
float fArray[], DataBuffer data) {
int Offset=0;
int x1 = x + w;
int y1 = y + h;
for (int i=y; i<(y+h); i++) {
for (int j=x; j<(x+w); j++) {
if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
{
throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
}
for (int i=y; i<y1; i++) {
for (int j=x; j<x1; j++) {
setSample(j, i, b, fArray[Offset++], data);
}
}
@ -1375,9 +1390,18 @@ public abstract class SampleModel
public void setSamples(int x, int y, int w, int h, int b,
double dArray[], DataBuffer data) {
int Offset=0;
int x1 = x + w;
int y1 = y + h;
for (int i=y; i<(y+h); i++) {
for (int j=x; j<(x+w); j++) {
if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
y < 0 || y >= height || h > height || y1 < 0 || y1 > height)
{
throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
}
for (int i=y; i<y1; i++) {
for (int j=x; j<x1; j++) {
setSample(j, i, b, dArray[Offset++], data);
}
}

View File

@ -23,9 +23,9 @@
/*
* @test
* @bug 6735275
* @summary Test verifies that SampleModel.getSamples() throws an appropriate
* exception if coordinates are not in bounds.
* @bug 6735275 6993561
* @summary Test verifies that SampleModel.getSamples() SampleModel.setSamples()
* throw an appropriate exception if coordinates are not in bounds.
*
* @run main GetSamplesTest
*/
@ -75,6 +75,7 @@ public class GetSamplesTest {
try {
sm.getSamples(Integer.MAX_VALUE, 0, 1, 1, 0, iArray, db);
sm.setSamples(Integer.MAX_VALUE, 0, 1, 1, 0, iArray, db);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage());
iOk = true;
@ -82,6 +83,7 @@ public class GetSamplesTest {
try {
sm.getSamples(Integer.MAX_VALUE, 0, 1, 1, 0, fArray, db);
sm.setSamples(Integer.MAX_VALUE, 0, 1, 1, 0, fArray, db);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage());
fOk = true;
@ -89,6 +91,7 @@ public class GetSamplesTest {
try {
sm.getSamples(0, Integer.MAX_VALUE, 1, 1, 0, dArray, db);
sm.setSamples(0, Integer.MAX_VALUE, 1, 1, 0, dArray, db);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage());
dOk = true;