On Wed, 19 Mar 2025 13:06:56 GMT, Nikita Gubarkov <[email protected]> wrote:
>> 8352407: PixelInterleavedSampleModel with unused components throws
>> RasterFormatException: Incorrect pixel stride
>
> Nikita Gubarkov has updated the pull request incrementally with one
> additional commit since the last revision:
>
> The previous approach was wrong for non-pixel interleaving.
>
> Just align the buffer size to the pixel stride instead, should be better.
One definite issue with this fix is that it assumes pixelStride !=0
The spec (at least as far back as JDK 1.3) has allowed pixelStride == 0
So this following code is broken with this change
import java.awt.image.*;
public class Z {
public static void main(String[] args) {
int[] offsets = {0};
new ComponentSampleModel(DataBufferInt.TYPE_INT, 1, 1, 0, 0, offsets);
}
}
% java Z
Exception in thread "main" java.lang.ArithmeticException: / by zero
at
java.desktop/java.awt.image.ComponentSampleModel.getBufferSize(ComponentSampleModel.java:284)
at
java.desktop/java.awt.image.ComponentSampleModel.verify(ComponentSampleModel.java:240)
at
java.desktop/java.awt.image.ComponentSampleModel.<init>(ComponentSampleModel.java:155)
at Z.main(Z.java:6)
-------------
PR Comment: https://git.openjdk.org/jdk/pull/24111#issuecomment-2867910475