Skip to content

Commit 102d8f6

Browse files
committed
matrix.cpp::setSize(): fixed out-of-bounds access on cv::Mat steps
1 parent a5b8f16 commit 102d8f6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

modules/core/src/matrix.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,19 @@ void setSize( Mat& m, int _dims, const int* _sz, const size_t* _steps, bool auto
237237

238238
if( _steps )
239239
{
240-
if (_steps[i] % esz1 != 0)
240+
if (i < _dims-1)
241241
{
242-
CV_Error(Error::BadStep, "Step must be a multiple of esz1");
243-
}
242+
if (_steps[i] % esz1 != 0)
243+
{
244+
CV_Error_(Error::BadStep, ("Step %zu for dimension %d must be a multiple of esz1 %zu", _steps[i], i, esz1));
245+
}
244246

245-
m.step.p[i] = i < _dims-1 ? _steps[i] : esz;
247+
m.step.p[i] = _steps[i];
248+
}
249+
else
250+
{
251+
m.step.p[i] = esz;
252+
}
246253
}
247254
else if( autoSteps )
248255
{

0 commit comments

Comments
 (0)