1 /*
2 * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1371 /* Need to re-verify the dimensions since a sample model may be
1372 * specified to the constructor
1373 */
1374 if (width <= 0 || height <= 0 ||
1375 height > (Integer.MAX_VALUE / width))
1376 {
1377 throw new RasterFormatException("Invalid raster dimension");
1378 }
1379
1380
1381 /*
1382 * pixelBitstride was verified in constructor, so just make
1383 * sure that it is safe to multiply it by width.
1384 */
1385 if ((width - 1) > Integer.MAX_VALUE / pixelBitStride) {
1386 throw new RasterFormatException("Invalid raster dimension");
1387 }
1388
1389 if (scanlineStride < 0 ||
1390 scanlineStride > (Integer.MAX_VALUE / height) ||
1391 scanlineStride > data.length)
1392 {
1393 throw new RasterFormatException("Invalid scanline stride");
1394 }
1395
1396 int lastbit = (dataBitOffset
1397 + (height-1) * scanlineStride * 8
1398 + (width-1) * pixelBitStride
1399 + pixelBitStride - 1);
1400 if (lastbit < 0 || lastbit / 8 >= data.length) {
1401 throw new RasterFormatException("raster dimensions overflow " +
1402 "array bounds");
1403 }
1404 if (strictCheck) {
1405 if (height > 1) {
1406 lastbit = width * pixelBitStride - 1;
1407 if (lastbit / 8 >= scanlineStride) {
1408 throw new RasterFormatException("data for adjacent" +
1409 " scanlines overlaps");
1410 }
1411 }
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1371 /* Need to re-verify the dimensions since a sample model may be
1372 * specified to the constructor
1373 */
1374 if (width <= 0 || height <= 0 ||
1375 height > (Integer.MAX_VALUE / width))
1376 {
1377 throw new RasterFormatException("Invalid raster dimension");
1378 }
1379
1380
1381 /*
1382 * pixelBitstride was verified in constructor, so just make
1383 * sure that it is safe to multiply it by width.
1384 */
1385 if ((width - 1) > Integer.MAX_VALUE / pixelBitStride) {
1386 throw new RasterFormatException("Invalid raster dimension");
1387 }
1388
1389 if (scanlineStride < 0 ||
1390 scanlineStride > (Integer.MAX_VALUE / height) ||
1391 (height > 1 && scanlineStride > data.length))
1392 {
1393 throw new RasterFormatException("Invalid scanline stride");
1394 }
1395
1396 int lastbit = (dataBitOffset
1397 + (height-1) * scanlineStride * 8
1398 + (width-1) * pixelBitStride
1399 + pixelBitStride - 1);
1400 if (lastbit < 0 || lastbit / 8 >= data.length) {
1401 throw new RasterFormatException("raster dimensions overflow " +
1402 "array bounds");
1403 }
1404 if (strictCheck) {
1405 if (height > 1) {
1406 lastbit = width * pixelBitStride - 1;
1407 if (lastbit / 8 >= scanlineStride) {
1408 throw new RasterFormatException("data for adjacent" +
1409 " scanlines overlaps");
1410 }
1411 }
|