From 6c575e882664443c633196fea38a0605f0a3a118 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 21 Sep 2020 18:10:33 +0000 Subject: [PATCH] imgcodecs(openjpeg): add checks for input --- .../imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp b/modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp index 8a9096b8d5..149b34c927 100644 --- a/modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp +++ b/modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp @@ -634,6 +634,23 @@ bool Jpeg2KOpjDecoder::readData( Mat& img ) cv::format("OpenJPEG2000: output precision > 16 not supported: target depth %d", depth)); }(); const uint8_t shift = outPrec > m_maxPrec ? 0 : (uint8_t)(m_maxPrec - outPrec); // prec <= 64 + + const int inChannels = image_->numcomps; + + CV_Assert(inChannels > 0); + CV_Assert(image_->comps); + for (int c = 0; c < inChannels; c++) + { + const opj_image_comp_t& comp = image_->comps[c]; + CV_CheckEQ((int)comp.dx, 1, "OpenJPEG2000: tiles are not supported"); + CV_CheckEQ((int)comp.dy, 1, "OpenJPEG2000: tiles are not supported"); + CV_CheckEQ((int)comp.x0, 0, "OpenJPEG2000: tiles are not supported"); + CV_CheckEQ((int)comp.y0, 0, "OpenJPEG2000: tiles are not supported"); + CV_CheckEQ((int)comp.w, img.cols, "OpenJPEG2000: tiles are not supported"); + CV_CheckEQ((int)comp.h, img.rows, "OpenJPEG2000: tiles are not supported"); + CV_Assert(comp.data && "OpenJPEG2000: missing component data (unsupported / broken input)"); + } + return decode(*image_, img, shift); }