-
Bug
-
Resolution: Unresolved
-
P3
-
9, 11, 17, 21, 24
-
None
-
In Review
Raster creation from PixelInterleavedSampleModel with unused components and w=h=1 throws "RasterFormatException: Incorrect pixel stride".
I noticed this when working on a Vulkan rendering implementation.
Consider simple example:
We want 4-byte RGBx (no alpha) with the last component unused:
```
int width = 1, height = 1;
SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, width, height, 4, width*4, new int[] {0, 1, 2});
WritableRaster raster = Raster.createWritableRaster(sm, null);
```
Note that this only fails when w=h=1
This is because `ComponentSampleModel.getBufferSize()` effectively "cuts" last unused data elements, thus causing the size of data array to not be multiple of pixel/scanline stride. Not only it fails the verification when w=h=1 (and therefore data array is smaller than pixel stride), but it is also dangerous overall, as the data may be copied by `memcpy`, causing out-of-bounds access under usual assumptions (scanlineStride % pixelStride == 0 && dataSize >= height * scanlineStride && etc...).
I noticed this when working on a Vulkan rendering implementation.
Consider simple example:
We want 4-byte RGBx (no alpha) with the last component unused:
```
int width = 1, height = 1;
SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, width, height, 4, width*4, new int[] {0, 1, 2});
WritableRaster raster = Raster.createWritableRaster(sm, null);
```
Note that this only fails when w=h=1
This is because `ComponentSampleModel.getBufferSize()` effectively "cuts" last unused data elements, thus causing the size of data array to not be multiple of pixel/scanline stride. Not only it fails the verification when w=h=1 (and therefore data array is smaller than pixel stride), but it is also dangerous overall, as the data may be copied by `memcpy`, causing out-of-bounds access under usual assumptions (scanlineStride % pixelStride == 0 && dataSize >= height * scanlineStride && etc...).
- relates to
-
JDK-6353518 Creation of a WritableRaster with a custom DataBuffer causes erroneous Exception
-
- Resolved
-
- links to
-
Review(master) openjdk/jdk/24111