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

Reviewed-by: jgodinez, prr
This commit is contained in:
Andrew Brygin 2011-03-22 12:28:03 +03:00
parent 91f8f158a4
commit f267ef101f
4 changed files with 96 additions and 18 deletions

View File

@ -408,7 +408,12 @@ public final class BandedSampleModel extends ComponentSampleModel
*/
public int[] getPixels(int x, int y, int w, int h,
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
("Coordinate out of bounds!");
}
@ -690,7 +695,12 @@ public final class BandedSampleModel extends ComponentSampleModel
*/
public void setPixels(int x, int y, int w, int h,
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
("Coordinate out of bounds!");
}

View File

@ -739,7 +739,12 @@ public class ComponentSampleModel extends SampleModel
*/
public int[] getPixels(int x, int y, int w, int h,
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
("Coordinate out of bounds!");
}
@ -1025,7 +1030,12 @@ public class ComponentSampleModel extends SampleModel
*/
public void setPixels(int x, int y, int w, int h,
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
("Coordinate out of bounds!");
}

View File

@ -759,14 +759,22 @@ public abstract class SampleModel
int pixels[];
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)
pixels = iArray;
else
pixels = new int[numBands * w * h];
for (int i=y; i<(h+y); i++) {
for (int j=x; j<(w+x); j++) {
for (int i=y; i<y1; i++) {
for (int j=x; j<x1; j++) {
for(int k=0; k<numBands; k++) {
pixels[Offset++] = getSample(j, i, k, data);
}
@ -799,14 +807,22 @@ public abstract class SampleModel
float pixels[];
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)
pixels = fArray;
else
pixels = new float[numBands * w * h];
for (int i=y; i<(h+y); i++) {
for(int j=x; j<(w+x); j++) {
for (int i=y; i<y1; i++) {
for(int j=x; j<x1; j++) {
for(int k=0; k<numBands; k++) {
pixels[Offset++] = getSampleFloat(j, i, k, data);
}
@ -838,6 +854,14 @@ public abstract class SampleModel
double dArray[], DataBuffer data) {
double pixels[];
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)
pixels = dArray;
@ -845,8 +869,8 @@ public abstract class SampleModel
pixels = new double[numBands * w * h];
// Fix 4217412
for (int i=y; i<(h+y); i++) {
for (int j=x; j<(w+x); j++) {
for (int i=y; i<y1; i++) {
for (int j=x; j<x1; j++) {
for (int k=0; k<numBands; k++) {
pixels[Offset++] = getSampleDouble(j, i, k, data);
}
@ -1146,9 +1170,17 @@ public abstract class SampleModel
public void setPixels(int x, int y, int w, int h,
int iArray[], 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++) {
for (int k=0; k<numBands; k++) {
setSample(j, i, k, iArray[Offset++], data);
}
@ -1176,9 +1208,17 @@ public abstract class SampleModel
public void setPixels(int x, int y, int w, int h,
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++) {
for(int k=0; k<numBands; k++) {
setSample(j, i, k, fArray[Offset++], data);
}
@ -1206,9 +1246,17 @@ public abstract class SampleModel
public void setPixels(int x, int y, int w, int h,
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++) {
for (int k=0; k<numBands; k++) {
setSample(j, i, k, dArray[Offset++], data);
}

View File

@ -461,7 +461,12 @@ public class SinglePixelPackedSampleModel extends SampleModel
*/
public int[] getPixels(int x, int y, int w, int h,
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
("Coordinate out of bounds!");
}
@ -659,7 +664,12 @@ public class SinglePixelPackedSampleModel extends SampleModel
*/
public void setPixels(int x, int y, int w, int h,
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
("Coordinate out of bounds!");
}