src/share/classes/sun/awt/image/BytePackedRaster.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, 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. Oracle designates this
@@ -1384,17 +1384,32 @@
*/
if ((width - 1) > Integer.MAX_VALUE / pixelBitStride) {
throw new RasterFormatException("Invalid raster dimension");
}
+ if ((long)minX - sampleModelTranslateX < 0 ||
+ (long)minY - sampleModelTranslateY < 0) {
+
+ throw new RasterFormatException("Incorrect origin/translate: (" +
+ minX + ", " + minY + ") / (" +
+ sampleModelTranslateX + ", " + sampleModelTranslateY + ")");
+ }
+
if (scanlineStride < 0 ||
- scanlineStride > (Integer.MAX_VALUE / height) ||
- scanlineStride > data.length)
+ scanlineStride > (Integer.MAX_VALUE / height))
{
throw new RasterFormatException("Invalid scanline stride");
}
+ if (height > 1 || minY - sampleModelTranslateY > 0) {
+ // buffer should contain at least one scanline
+ if (scanlineStride > data.length) {
+ throw new RasterFormatException("Incorrect scanline stride: "
+ + scanlineStride);
+ }
+ }
+
int lastbit = (dataBitOffset
+ (height-1) * scanlineStride * 8
+ (width-1) * pixelBitStride
+ pixelBitStride - 1);
if (lastbit < 0 || lastbit / 8 >= data.length) {