You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ay...@apache.org on 2007/01/30 16:02:55 UTC
svn commit: r501410 - in /harmony/enhanced/classlib/trunk/modules/awt/src:
main/java/common/java/awt/image/SinglePixelPackedSampleModel.java
test/api/java/common/java/awt/image/SinglePixelPackedSampleModelTest.java
Author: ayza
Date: Tue Jan 30 07:02:52 2007
New Revision: 501410
URL: http://svn.apache.org/viewvc?view=rev&rev=501410
Log:
Applying patch from HARMONY-2431 ([classlib][awt] SinglePixelPackedSampleModel.getSamples() expected ArrayIndexOutOfBoundsException)
Modified:
harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/SinglePixelPackedSampleModel.java
harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/SinglePixelPackedSampleModelTest.java
Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/SinglePixelPackedSampleModel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/SinglePixelPackedSampleModel.java?view=diff&rev=501410&r1=501409&r2=501410
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/SinglePixelPackedSampleModel.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/SinglePixelPackedSampleModel.java Tue Jan 30 07:02:52 2007
@@ -240,7 +240,8 @@
@Override
public int[] getPixels(int x, int y, int w, int h, int iArray[],
DataBuffer data) {
- if (x < 0 || y < 0 || x + w > this.width || y + h > this.height) {
+ if ((x < 0) || (y < 0) || ((long) x + (long) w > this.width)
+ || ((long) y + (long) h > this.height)) {
// awt.63=Coordinates are not in bounds
throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
}
@@ -268,9 +269,11 @@
@Override
public void setPixels(int x, int y, int w, int h, int iArray[],
DataBuffer data) {
- if (x < 0 || y < 0 || x + w > this.width || y + h > this.height) {
+ if ((x < 0) || (y < 0) || ((long) x + (long) w > this.width)
+ || ((long) y + (long) h > this.height)) {
// awt.63=Coordinates are not in bounds
- throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
+ throw new ArrayIndexOutOfBoundsException(Messages
+ .getString("awt.63")); //$NON-NLS-1$
}
int idx = 0;
@@ -299,9 +302,11 @@
@Override
public int[] getSamples(int x, int y, int w, int h, int b, int iArray[],
DataBuffer data) {
- if (x < 0 || y < 0 || x + w > this.width || y + h > this.height) {
+ if ((x < 0) || (y < 0) || ((long) x + (long) w > this.width)
+ || ((long) y + (long) h > this.height)) {
// awt.63=Coordinates are not in bounds
- throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
+ throw new ArrayIndexOutOfBoundsException(Messages
+ .getString("awt.63")); //$NON-NLS-1$
}
int samples[];
@@ -325,7 +330,8 @@
@Override
public void setSamples(int x, int y, int w, int h, int b, int iArray[],
DataBuffer data) {
- if (x < 0 || y < 0 || x + w > this.width || y + h > this.height) {
+ if ((x < 0) || (y < 0) || ((long) x + (long) w > this.width)
+ || ((long) y + (long) h > this.height)) {
// awt.63=Coordinates are not in bounds
throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
}
Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/SinglePixelPackedSampleModelTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/SinglePixelPackedSampleModelTest.java?view=diff&rev=501410&r1=501409&r2=501410
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/SinglePixelPackedSampleModelTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/SinglePixelPackedSampleModelTest.java Tue Jan 30 07:02:52 2007
@@ -840,6 +840,15 @@
assertTrue(Arrays.equals(rsamples, tsamples));
}
+ // Regression for HARMONY-2431
+ try {
+ new SinglePixelPackedSampleModel(3, 216, 1, new int[851])
+ .getSamples(6, 7, 14, Integer.MAX_VALUE, 0, new int[] { 0,
+ 0, 0 }, new DataBufferDouble(7, 5));
+ fail("ArrayIndexOutOfBoundsException was not thrown"); //$NON-NLS-1$
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ // expected
+ }
}
public final void testGetDataElements(){
@@ -1426,6 +1435,16 @@
for(int x = 0; x < w; x++){
assertEquals(idata[y * sppsmi2.getScanlineStride() + x], intTestData[idx++]);
}
+ }
+
+ // Regression for HARMONY-2431
+ try {
+ new SinglePixelPackedSampleModel(1, 127, 3, 0, new int[970])
+ .setPixels(Integer.MAX_VALUE, 1, 13, 1, new int[] {},
+ new DataBufferDouble(7, 5));
+ fail("ArrayIndexOutOfBoundsException was not thrown"); //$NON-NLS-1$
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ // expected
}
}