Skip to content

Commit f7b8f52

Browse files
committed
Merge pull request opencv#18374 from alalek:openjpeg_extra_checks
2 parents f6aa9ac + 6c575e8 commit f7b8f52

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,23 @@ bool Jpeg2KOpjDecoder::readData( Mat& img )
634634
cv::format("OpenJPEG2000: output precision > 16 not supported: target depth %d", depth));
635635
}();
636636
const uint8_t shift = outPrec > m_maxPrec ? 0 : (uint8_t)(m_maxPrec - outPrec); // prec <= 64
637+
638+
const int inChannels = image_->numcomps;
639+
640+
CV_Assert(inChannels > 0);
641+
CV_Assert(image_->comps);
642+
for (int c = 0; c < inChannels; c++)
643+
{
644+
const opj_image_comp_t& comp = image_->comps[c];
645+
CV_CheckEQ((int)comp.dx, 1, "OpenJPEG2000: tiles are not supported");
646+
CV_CheckEQ((int)comp.dy, 1, "OpenJPEG2000: tiles are not supported");
647+
CV_CheckEQ((int)comp.x0, 0, "OpenJPEG2000: tiles are not supported");
648+
CV_CheckEQ((int)comp.y0, 0, "OpenJPEG2000: tiles are not supported");
649+
CV_CheckEQ((int)comp.w, img.cols, "OpenJPEG2000: tiles are not supported");
650+
CV_CheckEQ((int)comp.h, img.rows, "OpenJPEG2000: tiles are not supported");
651+
CV_Assert(comp.data && "OpenJPEG2000: missing component data (unsupported / broken input)");
652+
}
653+
637654
return decode(*image_, img, shift);
638655
}
639656

0 commit comments

Comments
 (0)