team-charls / charls

CharLS, a C++ JPEG-LS library implementation
BSD 3-Clause "New" or "Revised" License
188 stars 74 forks source link

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

Closed mckee-mt closed 2 years ago

mckee-mt commented 2 years ago

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

vbaderks commented 2 years ago

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

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);