1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

core(matrix): Negative values checks

Add checks that prevents indexing an array by negative values.
This commit is contained in:
Jiri Kucera
2020-04-14 14:23:43 +02:00
parent 675342ecd9
commit ce31c9c448
2 changed files with 165 additions and 20 deletions
+12 -20
View File
@@ -947,7 +947,7 @@ bool _InputArray::isContinuous(int i) const
if( k == STD_ARRAY_MAT )
{
const Mat* vv = (const Mat*)obj;
CV_Assert(i > 0 && i < sz.height);
CV_Assert(i >= 0 && i < sz.height);
return vv[i].isContinuous();
}
@@ -981,21 +981,21 @@ bool _InputArray::isSubmatrix(int i) const
if( k == STD_VECTOR_MAT )
{
const std::vector<Mat>& vv = *(const std::vector<Mat>*)obj;
CV_Assert((size_t)i < vv.size());
CV_Assert(i >= 0 && (size_t)i < vv.size());
return vv[i].isSubmatrix();
}
if( k == STD_ARRAY_MAT )
{
const Mat* vv = (const Mat*)obj;
CV_Assert(i < sz.height);
CV_Assert(i >= 0 && i < sz.height);
return vv[i].isSubmatrix();
}
if( k == STD_VECTOR_UMAT )
{
const std::vector<UMat>& vv = *(const std::vector<UMat>*)obj;
CV_Assert((size_t)i < vv.size());
CV_Assert(i >= 0 && (size_t)i < vv.size());
return vv[i].isSubmatrix();
}
@@ -1026,9 +1026,7 @@ size_t _InputArray::offset(int i) const
if( k == STD_VECTOR_MAT )
{
const std::vector<Mat>& vv = *(const std::vector<Mat>*)obj;
if( i < 0 )
return 1;
CV_Assert( i < (int)vv.size() );
CV_Assert( i >= 0 && i < (int)vv.size() );
return (size_t)(vv[i].ptr() - vv[i].datastart);
}
@@ -1036,16 +1034,14 @@ size_t _InputArray::offset(int i) const
if( k == STD_ARRAY_MAT )
{
const Mat* vv = (const Mat*)obj;
if( i < 0 )
return 1;
CV_Assert( i < sz.height );
CV_Assert( i >= 0 && i < sz.height );
return (size_t)(vv[i].ptr() - vv[i].datastart);
}
if( k == STD_VECTOR_UMAT )
{
const std::vector<UMat>& vv = *(const std::vector<UMat>*)obj;
CV_Assert((size_t)i < vv.size());
CV_Assert(i >= 0 && (size_t)i < vv.size());
return vv[i].offset;
}
@@ -1059,7 +1055,7 @@ size_t _InputArray::offset(int i) const
if (k == STD_VECTOR_CUDA_GPU_MAT)
{
const std::vector<cuda::GpuMat>& vv = *(const std::vector<cuda::GpuMat>*)obj;
CV_Assert((size_t)i < vv.size());
CV_Assert(i >= 0 && (size_t)i < vv.size());
return (size_t)(vv[i].data - vv[i].datastart);
}
@@ -1089,25 +1085,21 @@ size_t _InputArray::step(int i) const
if( k == STD_VECTOR_MAT )
{
const std::vector<Mat>& vv = *(const std::vector<Mat>*)obj;
if( i < 0 )
return 1;
CV_Assert( i < (int)vv.size() );
CV_Assert( i >= 0 && i < (int)vv.size() );
return vv[i].step;
}
if( k == STD_ARRAY_MAT )
{
const Mat* vv = (const Mat*)obj;
if( i < 0 )
return 1;
CV_Assert( i < sz.height );
CV_Assert( i >= 0 && i < sz.height );
return vv[i].step;
}
if( k == STD_VECTOR_UMAT )
{
const std::vector<UMat>& vv = *(const std::vector<UMat>*)obj;
CV_Assert((size_t)i < vv.size());
CV_Assert(i >= 0 && (size_t)i < vv.size());
return vv[i].step;
}
@@ -1119,7 +1111,7 @@ size_t _InputArray::step(int i) const
if (k == STD_VECTOR_CUDA_GPU_MAT)
{
const std::vector<cuda::GpuMat>& vv = *(const std::vector<cuda::GpuMat>*)obj;
CV_Assert((size_t)i < vv.size());
CV_Assert(i >= 0 && (size_t)i < vv.size());
return vv[i].step;
}