提交 7fc5c7c4 编写于 作者: B bae

6773586: java.awt.image.SampleModel.getPixels() methods not allways throw...

6773586: java.awt.image.SampleModel.getPixels() methods not allways throw ArrayIndexOutOfBoundsException
Reviewed-by: jgodinez, prr
上级 0b0dc4d1
...@@ -408,7 +408,12 @@ public final class BandedSampleModel extends ComponentSampleModel ...@@ -408,7 +408,12 @@ public final class BandedSampleModel extends ComponentSampleModel
*/ */
public int[] getPixels(int x, int y, int w, int h, public int[] getPixels(int x, int y, int w, int h,
int iArray[], DataBuffer data) { int iArray[], DataBuffer data) {
if ((x < 0) || (y < 0) || (x + w > width) || (y + h > height)) { 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 throw new ArrayIndexOutOfBoundsException
("Coordinate out of bounds!"); ("Coordinate out of bounds!");
} }
...@@ -690,7 +695,12 @@ public final class BandedSampleModel extends ComponentSampleModel ...@@ -690,7 +695,12 @@ public final class BandedSampleModel extends ComponentSampleModel
*/ */
public void setPixels(int x, int y, int w, int h, public void setPixels(int x, int y, int w, int h,
int iArray[], DataBuffer data) { int iArray[], DataBuffer data) {
if ((x < 0) || (y < 0) || (x + w > width) || (y + h > height)) { 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 throw new ArrayIndexOutOfBoundsException
("Coordinate out of bounds!"); ("Coordinate out of bounds!");
} }
......
...@@ -739,7 +739,12 @@ public class ComponentSampleModel extends SampleModel ...@@ -739,7 +739,12 @@ public class ComponentSampleModel extends SampleModel
*/ */
public int[] getPixels(int x, int y, int w, int h, public int[] getPixels(int x, int y, int w, int h,
int iArray[], DataBuffer data) { int iArray[], DataBuffer data) {
if ((x < 0) || (y < 0) || (x + w > width) || (y + h > height)) { int x1 = x + w;
int y1 = y + h;
if (x < 0 || x >= width || w > width || x1 < 0 || x1 > width ||
y < 0 || y >= height || y > height || y1 < 0 || y1 > height)
{
throw new ArrayIndexOutOfBoundsException throw new ArrayIndexOutOfBoundsException
("Coordinate out of bounds!"); ("Coordinate out of bounds!");
} }
...@@ -1025,7 +1030,12 @@ public class ComponentSampleModel extends SampleModel ...@@ -1025,7 +1030,12 @@ public class ComponentSampleModel extends SampleModel
*/ */
public void setPixels(int x, int y, int w, int h, public void setPixels(int x, int y, int w, int h,
int iArray[], DataBuffer data) { int iArray[], DataBuffer data) {
if ((x < 0) || (y < 0) || (x + w > width) || (y + h > height)) { 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 throw new ArrayIndexOutOfBoundsException
("Coordinate out of bounds!"); ("Coordinate out of bounds!");
} }
......
...@@ -759,14 +759,22 @@ public abstract class SampleModel ...@@ -759,14 +759,22 @@ public abstract class SampleModel
int pixels[]; int pixels[];
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.");
}
if (iArray != null) if (iArray != null)
pixels = iArray; pixels = iArray;
else else
pixels = new int[numBands * w * h]; pixels = new int[numBands * w * h];
for (int i=y; i<(h+y); i++) { for (int i=y; i<y1; i++) {
for (int j=x; j<(w+x); j++) { for (int j=x; j<x1; j++) {
for(int k=0; k<numBands; k++) { for(int k=0; k<numBands; k++) {
pixels[Offset++] = getSample(j, i, k, data); pixels[Offset++] = getSample(j, i, k, data);
} }
...@@ -799,14 +807,22 @@ public abstract class SampleModel ...@@ -799,14 +807,22 @@ public abstract class SampleModel
float pixels[]; float pixels[];
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.");
}
if (fArray != null) if (fArray != null)
pixels = fArray; pixels = fArray;
else else
pixels = new float[numBands * w * h]; pixels = new float[numBands * w * h];
for (int i=y; i<(h+y); i++) { for (int i=y; i<y1; i++) {
for(int j=x; j<(w+x); j++) { for(int j=x; j<x1; j++) {
for(int k=0; k<numBands; k++) { for(int k=0; k<numBands; k++) {
pixels[Offset++] = getSampleFloat(j, i, k, data); pixels[Offset++] = getSampleFloat(j, i, k, data);
} }
...@@ -838,6 +854,14 @@ public abstract class SampleModel ...@@ -838,6 +854,14 @@ public abstract class SampleModel
double dArray[], DataBuffer data) { double dArray[], DataBuffer data) {
double pixels[]; double pixels[];
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.");
}
if (dArray != null) if (dArray != null)
pixels = dArray; pixels = dArray;
...@@ -845,8 +869,8 @@ public abstract class SampleModel ...@@ -845,8 +869,8 @@ public abstract class SampleModel
pixels = new double[numBands * w * h]; pixels = new double[numBands * w * h];
// Fix 4217412 // Fix 4217412
for (int i=y; i<(h+y); i++) { for (int i=y; i<y1; i++) {
for (int j=x; j<(w+x); j++) { for (int j=x; j<x1; j++) {
for (int k=0; k<numBands; k++) { for (int k=0; k<numBands; k++) {
pixels[Offset++] = getSampleDouble(j, i, k, data); pixels[Offset++] = getSampleDouble(j, i, k, data);
} }
...@@ -1146,9 +1170,17 @@ public abstract class SampleModel ...@@ -1146,9 +1170,17 @@ public abstract class SampleModel
public void setPixels(int x, int y, int w, int h, public void setPixels(int x, int y, int w, int h,
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++) {
for (int k=0; k<numBands; k++) { for (int k=0; k<numBands; k++) {
setSample(j, i, k, iArray[Offset++], data); setSample(j, i, k, iArray[Offset++], data);
} }
...@@ -1176,9 +1208,17 @@ public abstract class SampleModel ...@@ -1176,9 +1208,17 @@ public abstract class SampleModel
public void setPixels(int x, int y, int w, int h, public void setPixels(int x, int y, int w, int h,
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++) {
for(int k=0; k<numBands; k++) { for(int k=0; k<numBands; k++) {
setSample(j, i, k, fArray[Offset++], data); setSample(j, i, k, fArray[Offset++], data);
} }
...@@ -1206,9 +1246,17 @@ public abstract class SampleModel ...@@ -1206,9 +1246,17 @@ public abstract class SampleModel
public void setPixels(int x, int y, int w, int h, public void setPixels(int x, int y, int w, int h,
double dArray[], DataBuffer data) { double dArray[], 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++) {
for (int k=0; k<numBands; k++) { for (int k=0; k<numBands; k++) {
setSample(j, i, k, dArray[Offset++], data); setSample(j, i, k, dArray[Offset++], data);
} }
......
...@@ -461,7 +461,12 @@ public class SinglePixelPackedSampleModel extends SampleModel ...@@ -461,7 +461,12 @@ public class SinglePixelPackedSampleModel extends SampleModel
*/ */
public int[] getPixels(int x, int y, int w, int h, public int[] getPixels(int x, int y, int w, int h,
int iArray[], DataBuffer data) { int iArray[], DataBuffer data) {
if ((x < 0) || (y < 0) || (x + w > width) || (y + h > height)) { 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 throw new ArrayIndexOutOfBoundsException
("Coordinate out of bounds!"); ("Coordinate out of bounds!");
} }
...@@ -659,7 +664,12 @@ public class SinglePixelPackedSampleModel extends SampleModel ...@@ -659,7 +664,12 @@ public class SinglePixelPackedSampleModel extends SampleModel
*/ */
public void setPixels(int x, int y, int w, int h, public void setPixels(int x, int y, int w, int h,
int iArray[], DataBuffer data) { int iArray[], DataBuffer data) {
if ((x < 0) || (y < 0) || (x + w > width) || (y + h > height)) { 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 throw new ArrayIndexOutOfBoundsException
("Coordinate out of bounds!"); ("Coordinate out of bounds!");
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册