Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8352407

PixelInterleavedSampleModel with unused components throws RasterFormatException: Incorrect pixel stride

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • 9, 11, 17, 21, 24
    • client-libs
    • None
    • 2d
    • 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...).

            ngubarkov Nikita Gubarkov
            ngubarkov Nikita Gubarkov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: