Merge pull request #20823 from AleksandrPanov:fix_orb_integer_overflow

Fix ORB integer overflow

* set size_t step to fix integer overflow in ptr0 offset

* added issue_537 test

* minor fix tags, points

* added size_t_step and offset to remove mixed unsigned and signed operations

* features2d: update ORB checks

Co-authored-by: Alexander Alekhin <alexander.a.alekhin@gmail.com>
This commit is contained in:
Alexander Panov
2021-10-08 01:46:25 +03:00
committed by GitHub
parent fac895d7ba
commit dfc94c58f0
2 changed files with 34 additions and 3 deletions
+8 -3
View File
@@ -131,12 +131,17 @@ static void
HarrisResponses(const Mat& img, const std::vector<Rect>& layerinfo,
std::vector<KeyPoint>& pts, int blockSize, float harris_k)
{
CV_Assert( img.type() == CV_8UC1 && blockSize*blockSize <= 2048 );
CV_CheckTypeEQ(img.type(), CV_8UC1, "");
CV_CheckGT(blockSize, 0, "");
CV_CheckLE(blockSize*blockSize, 2048, "");
size_t ptidx, ptsize = pts.size();
const uchar* ptr00 = img.ptr<uchar>();
int step = (int)(img.step/img.elemSize1());
size_t size_t_step = img.step;
CV_CheckLE(size_t_step * blockSize + blockSize + 1, (size_t)INT_MAX, ""); // ofs computation, step+1
int step = static_cast<int>(size_t_step);
int r = blockSize/2;
float scale = 1.f/((1 << 2) * blockSize * 255.f);
@@ -154,7 +159,7 @@ HarrisResponses(const Mat& img, const std::vector<Rect>& layerinfo,
int y0 = cvRound(pts[ptidx].pt.y);
int z = pts[ptidx].octave;
const uchar* ptr0 = ptr00 + (y0 - r + layerinfo[z].y)*step + x0 - r + layerinfo[z].x;
const uchar* ptr0 = ptr00 + (y0 - r + layerinfo[z].y)*size_t_step + (x0 - r + layerinfo[z].x);
int a = 0, b = 0, c = 0;
for( int k = 0; k < blockSize*blockSize; k++ )