提交 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 ...@@ -1315,9 +1315,16 @@ public abstract class SampleModel
int iArray[], DataBuffer data) { int iArray[], DataBuffer data) {
int Offset=0; 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 i=y; i<y1; i++) {
for (int j=x; j<(x+w); j++) { for (int j=x; j<x1; j++) {
setSample(j, i, b, iArray[Offset++], data); setSample(j, i, b, iArray[Offset++], data);
} }
} }
...@@ -1345,9 +1352,17 @@ public abstract class SampleModel ...@@ -1345,9 +1352,17 @@ public abstract class SampleModel
public void setSamples(int x, int y, int w, int h, int b, public void setSamples(int x, int y, int w, int h, int b,
float fArray[], DataBuffer data) { float fArray[], DataBuffer data) {
int Offset=0; int Offset=0;
int x1 = x + w;
int y1 = y + h;
for (int i=y; i<(y+h); i++) { if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
for (int j=x; j<(x+w); j++) { 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); setSample(j, i, b, fArray[Offset++], data);
} }
} }
...@@ -1375,9 +1390,18 @@ public abstract class SampleModel ...@@ -1375,9 +1390,18 @@ public abstract class SampleModel
public void setSamples(int x, int y, int w, int h, int b, public void setSamples(int x, int y, int w, int h, int b,
double dArray[], DataBuffer data) { double dArray[], DataBuffer data) {
int Offset=0; 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); setSample(j, i, b, dArray[Offset++], data);
} }
} }
......
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
/* /*
* @test * @test
* @bug 6735275 * @bug 6735275 6993561
* @summary Test verifies that SampleModel.getSamples() throws an appropriate * @summary Test verifies that SampleModel.getSamples() SampleModel.setSamples()
* exception if coordinates are not in bounds. * throw an appropriate exception if coordinates are not in bounds.
* *
* @run main GetSamplesTest * @run main GetSamplesTest
*/ */
...@@ -75,6 +75,7 @@ public class GetSamplesTest { ...@@ -75,6 +75,7 @@ public class GetSamplesTest {
try { try {
sm.getSamples(Integer.MAX_VALUE, 0, 1, 1, 0, iArray, db); 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) { } catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage()); System.out.println(e.getMessage());
iOk = true; iOk = true;
...@@ -82,6 +83,7 @@ public class GetSamplesTest { ...@@ -82,6 +83,7 @@ public class GetSamplesTest {
try { try {
sm.getSamples(Integer.MAX_VALUE, 0, 1, 1, 0, fArray, db); 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) { } catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage()); System.out.println(e.getMessage());
fOk = true; fOk = true;
...@@ -89,6 +91,7 @@ public class GetSamplesTest { ...@@ -89,6 +91,7 @@ public class GetSamplesTest {
try { try {
sm.getSamples(0, Integer.MAX_VALUE, 1, 1, 0, dArray, db); 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) { } catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage()); System.out.println(e.getMessage());
dOk = true; dOk = true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册