Skip to content

Fix some overflows in drawing.#22153

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
vrabaud:opencv_drawing
Jul 12, 2022
Merged

Fix some overflows in drawing.#22153
opencv-pushbot merged 1 commit intoopencv:3.4from
vrabaud:opencv_drawing

Conversation

@vrabaud
Copy link
Copy Markdown
Contributor

@vrabaud vrabaud commented Jun 24, 2022

Those were found through fuzzing.
I see there is some pessimization too: circle could have a for loop over the image in case the circle is not fully inside (instead of over the circle as done now).

Pull Request Readiness Checklist

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we should add some checks for input to avoid overflows instead?

Changing int -> int64 computations may affect performance on some platforms.

@vpisarev
Copy link
Copy Markdown
Contributor

in my opinion, the patch is perfectly fine. drawing functions in OpenCV are not speed champions, they could be done more efficient, of course, but the proposed change should not affect speed. It's just a few more clocks spent in coordinates handling. As for checks for the input - the problem is that the use case may be real. If we use 16 bits for fractional part and if the image is huge satellite image with more than 32K pixels in width/height, it can indeed overflow 32 bits. This is where 64-bit arithmetics may come handy.

@vpisarev vpisarev self-requested a review July 12, 2022 19:08
@opencv-pushbot opencv-pushbot merged commit 9140051 into opencv:3.4 Jul 12, 2022
@alalek
Copy link
Copy Markdown
Member

alalek commented Jul 23, 2022

Please take a look on build warnings from MSVS compiler: https://pullrequest.opencv.org/buildbot/builders/3_4-win64-vc14/builds/100002

C:\build\3_4-win64-vc14\opencv\modules\imgproc\src\drawing.cpp(1491): warning C4244: 'argument': conversion from 'int64_t' to 'int', possible loss of data [C:\build\3_4-win64-vc14\build\modules\imgproc\opencv_imgproc.vcxproj]
C:\build\3_4-win64-vc14\opencv\modules\imgproc\src\drawing.cpp(1492): warning C4244: 'argument': conversion from 'int64_t' to 'int', possible loss of data [C:\build\3_4-win64-vc14\build\modules\imgproc\opencv_imgproc.vcxproj]
C:\build\3_4-win64-vc14\opencv\modules\imgproc\src\drawing.cpp(1507): warning C4244: 'argument': conversion from 'int64_t' to 'int', possible loss of data [C:\build\3_4-win64-vc14\build\modules\imgproc\opencv_imgproc.vcxproj]
C:\build\3_4-win64-vc14\opencv\modules\imgproc\src\drawing.cpp(1508): warning C4244: 'argument': conversion from 'int64_t' to 'int', possible loss of data [C:\build\3_4-win64-vc14\build\modules\imgproc\opencv_imgproc.vcxproj]
C:\build\3_4-win64-vc14\opencv\modules\imgproc\src\drawing.cpp(1531): warning C4244: 'argument': conversion from 'int64_t' to 'int', possible loss of data [C:\build\3_4-win64-vc14\build\modules\imgproc\opencv_imgproc.vcxproj]
C:\build\3_4-win64-vc14\opencv\modules\imgproc\src\drawing.cpp(1546): warning C4244: 'argument': conversion from 'int64_t' to 'int', possible loss of data [C:\build\3_4-win64-vc14\build\modules\imgproc\opencv_imgproc.vcxproj]
C:\build\3_4-win64-vc14\opencv\modules\imgproc\src\drawing.cpp(1569): warning C4244: 'argument': conversion from 'int64_t' to 'int', possible loss of data [C:\build\3_4-win64-vc14\build\modules\imgproc\opencv_imgproc.vcxproj]
C:\build\3_4-win64-vc14\opencv\modules\imgproc\src\drawing.cpp(1584): warning C4244: 'argument': conversion from 'int64_t' to 'int', possible loss of data [C:\build\3_4-win64-vc14\build\modules\imgproc\opencv_imgproc.vcxproj]

edge[0].dx = edge[1].dx = 0;

ptr += img.step*y;
ptr += (int64_t)img.step*y;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int64_t is C++11 stuff and it is not available on 3.4 branch.
3.4 branch must use cv::int64 instead.

@alalek alalek mentioned this pull request Jul 26, 2022
This was referenced Aug 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants