# HG changeset patch # User bae # Date 1300786083 -10800 # Node ID 8e3cd84800e3d589d1911adb727d0a40bad0c333 # Parent 38ffd0c8fd2b7c36864e34fffa7794d3f6c37abd 6773586: java.awt.image.SampleModel.getPixels() methods not allways throw ArrayIndexOutOfBoundsException Reviewed-by: jgodinez, prr diff -r 38ffd0c8fd2b -r 8e3cd84800e3 jdk/src/share/classes/java/awt/image/BandedSampleModel.java --- a/jdk/src/share/classes/java/awt/image/BandedSampleModel.java Tue Mar 22 11:22:38 2011 +0300 +++ b/jdk/src/share/classes/java/awt/image/BandedSampleModel.java Tue Mar 22 12:28:03 2011 +0300 @@ -408,7 +408,12 @@ */ 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 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 -r 38ffd0c8fd2b -r 8e3cd84800e3 jdk/src/share/classes/java/awt/image/ComponentSampleModel.java --- a/jdk/src/share/classes/java/awt/image/ComponentSampleModel.java Tue Mar 22 11:22:38 2011 +0300 +++ b/jdk/src/share/classes/java/awt/image/ComponentSampleModel.java Tue Mar 22 12:28:03 2011 +0300 @@ -739,7 +739,12 @@ */ 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 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 -r 38ffd0c8fd2b -r 8e3cd84800e3 jdk/src/share/classes/java/awt/image/SampleModel.java --- a/jdk/src/share/classes/java/awt/image/SampleModel.java Tue Mar 22 11:22:38 2011 +0300 +++ b/jdk/src/share/classes/java/awt/image/SampleModel.java Tue Mar 22 12:28:03 2011 +0300 @@ -759,14 +759,22 @@ 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 @@ 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= 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 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 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!"); }