Conversation
modules/features2d/src/orb.cpp
Outdated
|
|
||
| const uchar* ptr00 = img.ptr<uchar>(); | ||
| int step = (int)(img.step/img.elemSize1()); | ||
| size_t step = img.step/img.elemSize1(); |
There was a problem hiding this comment.
BTW, This would not help for 32-bit builds (sizeof(size_t) == 4).
We don't really want to support them (due to limited of available memory for such configuration).
So could you please to add CV_Check to catch overflow case below.
There was a problem hiding this comment.
integer overflow happens here:
const uchar* ptr0 = ptr00 + (y0 - r + layerinfo[z].y)*step + x0 - r + layerinfo[z].x;
ptr00 is pointer to begin image, (y0 - r + layerinfo[z].y)*step + x0 - r + layerinfo[z].x is offset, and offset is less then image size.
Сan 32 bit systems create a image larger than max(size_t)?
// sizeof(size_t) == 4 byte, image has one CV_8U channel
There was a problem hiding this comment.
If a 32-bit system cannot create the image larger than max(size_t), then the offset will not overflow.
There was a problem hiding this comment.
OK, probably it would fail earlier on image creation.
modules/features2d/test/test_orb.cpp
Outdated
| applyTestTag(CV_TEST_TAG_LONG); | ||
| applyTestTag(CV_TEST_TAG_DEBUG_VERYLONG); | ||
| applyTestTag(CV_TEST_TAG_MEMORY_6GB); |
modules/features2d/test/test_orb.cpp
Outdated
| point1 = {border + i * 100, border + i * 100}; | ||
| point2 = {width - border - i * 100, height - border * i * 100}; |
There was a problem hiding this comment.
C++98 doesn't support initializer list. Use ctors:
Point point1(border + i * 100, border + i * 100);
Point point2(width - border - i * 100, height - border * i * 100);
Use Point instead of cv::Vec2i
modules/features2d/test/test_orb.cpp
Outdated
| Ptr<ORB> orbPtr = ORB::create(31); | ||
| std::vector<KeyPoint> kps; | ||
| Mat fv; |
There was a problem hiding this comment.
Declare variable where are they used (this significantly increases code readability).
Right before detectAndCompute() call.
a7ac94d to
d7fbeb8
Compare
|
Please eliminate Windows warnings. |
There is problem in this lines:
|
modules/features2d/src/orb.cpp
Outdated
| const uchar* ptr00 = img.ptr<uchar>(); | ||
| int step = (int)(img.step/img.elemSize1()); | ||
| size_t size_t_step = img.step/img.elemSize1(); | ||
| CV_Check(size_t_step, size_t_step <= INT_MAX, "step in img > INT_MAX"); |
There was a problem hiding this comment.
This check doesn't prevent overflow below with step+1 expressions.
BTW, UBSAN can detect these overflows, but it dislikes negative indexing.
There was a problem hiding this comment.
Thx, fixed:
CV_Check(size_t_step, size_t_step + 1 <= INT_MAX, "step in img > INT_MAX");
There was a problem hiding this comment.
One more step usage is in ofs calculation.
BTW, step in test case is 25072
I will add commit with checks.
c2b34c0 to
e79c128
Compare
e79c128 to
ee98a00
Compare
Fixes opencv/opencv-python#537 "segmentation fault using ORB"
const uchar* ptr0 = ptr00 + (y0 - r + layerinfo[z].y)*step + x0 - r + layerinfo[z].x;stepwas declared assize_t.PERF_TEST_P(feature2d, detectAndExtract, testing::Combine(testing::Values(DETECTORS_EXTRACTORS), TEST_IMAGES))And the performance remained almost unchanged:
test_new_version.txt
test_old_version.txt
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.