提交 5940c98c 编写于 作者: B bae

6773022: java.awt.image.SampleModel.getDataElements() does't throw...

6773022: java.awt.image.SampleModel.getDataElements() does't throw ArrayIndexOutOfBoundsEx for Integer.MAX_V
Reviewed-by: igor, prr
上级 19c8cb7a
...@@ -358,6 +358,15 @@ public abstract class SampleModel ...@@ -358,6 +358,15 @@ public abstract class SampleModel
int cnt = 0; int cnt = 0;
Object o = null; Object o = null;
int x1 = x + w;
int y1 = y + h;
if (x < 0 || x1 < x || x1 > width ||
y < 0 || y1 < y || y1 > height)
{
throw new ArrayIndexOutOfBoundsException("Invalid coordinates.");
}
switch(type) { switch(type) {
case DataBuffer.TYPE_BYTE: case DataBuffer.TYPE_BYTE:
...@@ -370,8 +379,8 @@ public abstract class SampleModel ...@@ -370,8 +379,8 @@ public abstract class SampleModel
else else
bdata = (byte[])obj; bdata = (byte[])obj;
for (int i=y; i<y+h; i++) { for (int i=y; i<y1; i++) {
for (int j=x; j<x+w; j++) { for (int j=x; j<x1; j++) {
o = getDataElements(j, i, o, data); o = getDataElements(j, i, o, data);
btemp = (byte[])o; btemp = (byte[])o;
for (int k=0; k<numDataElems; k++) { for (int k=0; k<numDataElems; k++) {
...@@ -393,8 +402,8 @@ public abstract class SampleModel ...@@ -393,8 +402,8 @@ public abstract class SampleModel
else else
sdata = (short[])obj; sdata = (short[])obj;
for (int i=y; i<y+h; i++) { for (int i=y; i<y1; i++) {
for (int j=x; j<x+w; j++) { for (int j=x; j<x1; j++) {
o = getDataElements(j, i, o, data); o = getDataElements(j, i, o, data);
stemp = (short[])o; stemp = (short[])o;
for (int k=0; k<numDataElems; k++) { for (int k=0; k<numDataElems; k++) {
...@@ -416,8 +425,8 @@ public abstract class SampleModel ...@@ -416,8 +425,8 @@ public abstract class SampleModel
else else
idata = (int[])obj; idata = (int[])obj;
for (int i=y; i<y+h; i++) { for (int i=y; i<y1; i++) {
for (int j=x; j<x+w; j++) { for (int j=x; j<x1; j++) {
o = getDataElements(j, i, o, data); o = getDataElements(j, i, o, data);
itemp = (int[])o; itemp = (int[])o;
for (int k=0; k<numDataElems; k++) { for (int k=0; k<numDataElems; k++) {
...@@ -439,8 +448,8 @@ public abstract class SampleModel ...@@ -439,8 +448,8 @@ public abstract class SampleModel
else else
fdata = (float[])obj; fdata = (float[])obj;
for (int i=y; i<y+h; i++) { for (int i=y; i<y1; i++) {
for (int j=x; j<x+w; j++) { for (int j=x; j<x1; j++) {
o = getDataElements(j, i, o, data); o = getDataElements(j, i, o, data);
ftemp = (float[])o; ftemp = (float[])o;
for (int k=0; k<numDataElems; k++) { for (int k=0; k<numDataElems; k++) {
...@@ -462,8 +471,8 @@ public abstract class SampleModel ...@@ -462,8 +471,8 @@ public abstract class SampleModel
else else
ddata = (double[])obj; ddata = (double[])obj;
for (int i=y; i<y+h; i++) { for (int i=y; i<y1; i++) {
for (int j=x; j<x+w; j++) { for (int j=x; j<x1; j++) {
o = getDataElements(j, i, o, data); o = getDataElements(j, i, o, data);
dtemp = (double[])o; dtemp = (double[])o;
for (int k=0; k<numDataElems; k++) { for (int k=0; k<numDataElems; k++) {
......
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6773022
* @summary Test verifies that SampleModel.getDataElements() throws an appropriate
* exception if coordinates are not in bounds.
*
* @run main GetDataElementsTest
*/
import java.awt.image.ComponentSampleModel;
import java.awt.image.DataBuffer;
import java.awt.image.SampleModel;
public class GetDataElementsTest {
public static int width = 100;
public static int height = 100;
public static int dataType = DataBuffer.TYPE_BYTE;
public static int numBands = 4;
public static void main(String[] args) {
SampleModel sm = new ComponentSampleModel(dataType, width, height, 4, width * 4, new int[] { 0, 1, 2, 3 } );
DataBuffer db = sm.createDataBuffer();
Object o = null;
boolean testPassed = false;
try {
o = sm.getDataElements(Integer.MAX_VALUE, 0, 1, 1, o, db);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage());
testPassed = true;
}
if (!testPassed) {
throw new RuntimeException("Excpected excprion was not thrown.");
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册