team-charls/charls

Multi component image with interleave mode none is not correctly decoded when a custom stride argument is used

Closed this issue · 1 comments

Hi.

When decoding an image with interleave_mode::none and RGB (component_count=3), the argument stride (!=0) seems not to be reflected well.

I think that it is good to change the following parts of the jpeg_stream_reader::decode() function.


//    const int64_t bytes_per_plane{static_cast<int64_t>(rect_.Width) * rect_.Height *
//                                  bit_to_byte_count(frame_info_.bits_per_sample)};
    const int64_t bytes_per_plane{static_cast<int64_t>(stride) * rect_.Height};

//    if (UNLIKELY(static_cast<int64_t>(destination.size) < bytes_per_plane * frame_info_.component_count))
//        throw_jpegls_error(jpegls_errc::destination_buffer_too_small);
    if (UNLIKELY(static_cast<int64_t>(destination.size) < bytes_per_plane))
        throw_jpegls_error(jpegls_errc::destination_buffer_too_small);

The commented out part is before the change.

K.Makiuchi

Thanks for the clear defect report. This defect has been resolved with 4e5334f

Remark: Buffer check needed to be:

if (UNLIKELY(static_cast<int64_t>(destination.size) < bytes_per_plane * plane_count))
        throw_jpegls_error(jpegls_errc::destination_buffer_too_small);