提交 0b0dc4d1 编写于 作者: B bae

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

6993561: java.awt.image.SampleModel.setSamples() methods not always throw ArrayIndexOutOfBoundsException
Reviewed-by: jgodinez, prr
上级 3b77a74a
......@@ -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);
}
}
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册