On Tue, 14 Oct 2025 17:45:41 GMT, Phil Race <[email protected]> wrote:

>> We seem to have a number of APIs that allow the strides to be zero.
>> I find them odd, but I don't see how they can cause an empty image and they 
>> need careful consideration before changing. It seems very deliberate.
>> Here's a sampling of other cases (there are likely more, I searched very 
>> briefly and crudely)
>> 
>> 
>>      * @throws IllegalArgumentException if {@code scanlineStride} is less 
>> than 0
>>     public BandedSampleModel(int dataType,
>>                              int w, int h,
>>                              int scanlineStride,
>>                              int[] bankIndices,
>>                              int[] bandOffsets) 
>> 
>> =====
>> 
>>      * @throws IllegalArgumentException if {@code pixelStride} is less than 0
>>      * @throws IllegalArgumentException if {@code scanlineStride} is less 
>> than 0
>>   public ComponentSampleModel(int dataType,
>>                                 int w, int h,
>>                                 int pixelStride,
>>                                 int scanlineStride,
>>                                 int[] bandOffsets) {
>> 
>> =====
>>      * @throws IllegalArgumentException if {@code pixelStride} is less than 0
>>      * @throws IllegalArgumentException if {@code scanlineStride} is less 
>> than 0
>>    public ComponentSampleModel(int dataType,
>>                                 int w, int h,
>>                                 int pixelStride,
>>                                 int scanlineStride,
>>                                 int[] bankIndices,
>>                                 int[] bandOffsets) {
>
> PS, also negative strides are something that we've been asked to support too 
> - in the distant past.
> But I don't have any plans to do it now.

>We seem to have a number of APIs that allow the strides to be zero.
>I find them odd, but I don't see how they can cause an empty image 

If the  scanlineStride and pixelStride are zero then the size below will be set 
to zero as well, even if we try to prevent that by checking the w and h to be > 
0 before.

lsz = (long)scanlineStride * (long)(h - 1) + // first (h - 1) scans
      (long)pixelStride * (long)w; // last scan
int size = (int)lsz;
.....
d = new DataBufferByte(size);

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27627#discussion_r2441597488

Reply via email to