From c8d5601a8a39f6a03e9fb18676f6458ea2ec5f1f Mon Sep 17 00:00:00 2001 From: Andrew Brygin Date: Tue, 29 Mar 2011 13:10:09 +0400 Subject: [PATCH] 7030147: java.awt.image.SampleModel.setDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_VA Reviewed-by: jgodinez, prr --- .../classes/java/awt/image/SampleModel.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/jdk/src/share/classes/java/awt/image/SampleModel.java b/jdk/src/share/classes/java/awt/image/SampleModel.java index e1437645e70..ab81b78d984 100644 --- a/jdk/src/share/classes/java/awt/image/SampleModel.java +++ b/jdk/src/share/classes/java/awt/image/SampleModel.java @@ -361,8 +361,8 @@ public abstract class SampleModel int x1 = x + w; int y1 = y + h; - if (x < 0 || x1 < x || x1 > width || - y < 0 || y1 < y || y1 > height) + 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."); } @@ -588,6 +588,15 @@ public abstract class SampleModel int type = getTransferType(); int numDataElems = getNumDataElements(); + 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."); + } + switch(type) { case DataBuffer.TYPE_BYTE: @@ -595,8 +604,8 @@ public abstract class SampleModel byte[] barray = (byte[])obj; byte[] btemp = new byte[numDataElems]; - for (int i=y; i