#195 ArrayIndexOutOfBoundsException for ResampleOp in certain cases

This commit is contained in:
Harald Kuhr 2015-11-27 13:20:44 +01:00
parent f21bc2089a
commit 6ce58dd682
2 changed files with 15 additions and 3 deletions

View File

@ -1465,7 +1465,7 @@ public class ResampleOp implements BufferedImageOp/* TODO: RasterOp */ {
for (int i = 0; i < dstHeight; i++) {
//contribY[i].n = 0;
contribY[i].p = new Contributor[(int) (width * 2.0 + 1)];
contribY[i].p = new Contributor[(int) (width * 2.0 + 1 + 0.5)];
double center = (double) i / yscale;
int left = (int) Math.ceil(center - width);
@ -1516,7 +1516,7 @@ public class ResampleOp implements BufferedImageOp/* TODO: RasterOp */ {
else {
for (int i = 0; i < dstHeight; ++i) {
//contribY[i].n = 0;
contribY[i].p = new Contributor[(int) (fwidth * 2 + 1)];
contribY[i].p = new Contributor[(int) (fwidth * 2 + 1 + 0.5)];
double center = (double) i / yscale;
double left = Math.ceil(center - fwidth);

View File

@ -69,7 +69,7 @@ public class ResampleOpTestCase {
}
private void assertResampleBufferedImageTypes(final int pFilterType) {
List<String> exceptions = new ArrayList<String>();
List<String> exceptions = new ArrayList<>();
// Test all image types in BufferedImage
for (int type = BufferedImage.TYPE_INT_ARGB; type <= BufferedImage.TYPE_BYTE_INDEXED; type++) {
@ -304,6 +304,18 @@ public class ResampleOpTestCase {
assertResampleBufferedImageTypes(ResampleOp.FILTER_LANCZOS);
}
// https://github.com/haraldk/TwelveMonkeys/issues/195
@Test
public void testAIOOBE() {
BufferedImage myImage = new BufferedImage(100, 354, BufferedImage.TYPE_INT_ARGB);
for (int i = 19; i > 0; i--) {
ResampleOp resampler = new ResampleOp(100, i, ResampleOp.FILTER_LANCZOS);
BufferedImage resizedImage = resampler.filter(myImage, null);
assertNotNull(resizedImage);
}
}
@Ignore("Not for general unit testing")
@Test
public void testTime() {