8300167: Add validation of the raster's layout before using in native

Reviewed-by: prr
This commit is contained in:
Sergey Bylokhov 2023-01-19 05:02:12 +00:00
parent 24cdcd4c70
commit 7348b9ec93

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2023, 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
@ -334,7 +334,8 @@ final class LCMSImageLayout {
ComponentSampleModel csm = (ComponentSampleModel)r.getSampleModel();
l.pixelType = CHANNELS_SH(br.getNumBands()) | BYTES_SH(1);
int numBands = br.getNumBands();
l.pixelType = CHANNELS_SH(numBands) | BYTES_SH(1);
int[] bandOffsets = csm.getBandOffsets();
BandOrder order = BandOrder.getBandOrder(bandOffsets);
@ -343,7 +344,7 @@ final class LCMSImageLayout {
switch (order) {
case INVERTED:
l.pixelType |= DOSWAP;
firstBand = csm.getNumBands() - 1;
firstBand = numBands - 1;
break;
case DIRECT:
// do nothing
@ -357,11 +358,14 @@ final class LCMSImageLayout {
l.nextPixelOffset = br.getPixelStride();
l.offset = br.getDataOffset(firstBand);
l.dataArray = br.getDataStorage();
l.dataType = DT_BYTE;
byte[] data = br.getDataStorage();
l.dataArray = data;
l.dataArrayLength = data.length;
l.width = br.getWidth();
l.height = br.getHeight();
l.verify();
return l;
}
return null;