imgcodecs(openjpeg): add checks for input
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Mon, 21 Sep 2020 18:10:33 +0000 (18:10 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Mon, 21 Sep 2020 18:10:51 +0000 (18:10 +0000)
modules/imgcodecs/src/grfmt_jpeg2000_openjpeg.cpp

index 8a9096b8d530745c1ddbf78b72ca9c7db6473d03..149b34c927737deaee44aef31e838324fd61a2df 100644 (file)
@@ -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);
 }