diff --git a/src/share/classes/java/awt/image/BandedSampleModel.java b/src/share/classes/java/awt/image/BandedSampleModel.java index 5a9acc50ae51acbf1f6ec993d969edc5b960558c..c1a620c7d8f3798b3c1cc3d813755fc5fd22b986 100644 --- a/src/share/classes/java/awt/image/BandedSampleModel.java +++ b/src/share/classes/java/awt/image/BandedSampleModel.java @@ -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!"); } diff --git a/src/share/classes/java/awt/image/ComponentSampleModel.java b/src/share/classes/java/awt/image/ComponentSampleModel.java index 12ce6189ad4979bdcd8b2e8b6420c78b7ea4bd32..627c9291074aa332144d4e84ec4a1fef6e100e02 100644 --- a/src/share/classes/java/awt/image/ComponentSampleModel.java +++ b/src/share/classes/java/awt/image/ComponentSampleModel.java @@ -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!"); } diff --git a/src/share/classes/java/awt/image/SampleModel.java b/src/share/classes/java/awt/image/SampleModel.java index 8b51116f75b908ea2f63596ae62f62a7af3c0309..e1437645e70b82aaf3a56d7350bbb6922172949f 100644 --- a/src/share/classes/java/awt/image/SampleModel.java +++ b/src/share/classes/java/awt/image/SampleModel.java @@ -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= 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= 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= 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= 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= 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 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!"); }