Merge pull request #23931 from asmorkalov:as/drawing_overflow

Fixed possible out-of-bound access in circles drawing
This commit is contained in:
Alexander Smorkalov 2023-07-21 12:28:14 +03:00 committed by GitHub
commit 09d2f4ea46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

10
modules/imgproc/src/drawing.cpp Executable file → Normal file
View File

@ -1556,7 +1556,7 @@ Circle( Mat& img, Point center, int radius, const void* color, int fill )
ICV_HLINE( tptr1, x21, x22, color, pix_size ); ICV_HLINE( tptr1, x21, x22, color, pix_size );
} }
} }
else if( x11 < size.width && x12 >= 0 && y21 < size.height && y22 >= 0 ) else if( x11 < size.width && x12 >= 0 && y21 < size.height && y22 >= 0)
{ {
if( fill ) if( fill )
{ {
@ -1564,7 +1564,7 @@ Circle( Mat& img, Point center, int radius, const void* color, int fill )
x12 = MIN( x12, size.width - 1 ); x12 = MIN( x12, size.width - 1 );
} }
if( (unsigned)y11 < (unsigned)size.height ) if( y11 >= 0 && y11 < size.height )
{ {
uchar *tptr = ptr + y11 * step; uchar *tptr = ptr + y11 * step;
@ -1579,7 +1579,7 @@ Circle( Mat& img, Point center, int radius, const void* color, int fill )
ICV_HLINE( tptr, x11, x12, color, pix_size ); ICV_HLINE( tptr, x11, x12, color, pix_size );
} }
if( (unsigned)y12 < (unsigned)size.height ) if( y12 >= 0 && y12 < size.height )
{ {
uchar *tptr = ptr + y12 * step; uchar *tptr = ptr + y12 * step;
@ -1602,7 +1602,7 @@ Circle( Mat& img, Point center, int radius, const void* color, int fill )
x22 = MIN( x22, size.width - 1 ); x22 = MIN( x22, size.width - 1 );
} }
if( (unsigned)y21 < (unsigned)size.height ) if( y21 >= 0 && y21 < size.height )
{ {
uchar *tptr = ptr + y21 * step; uchar *tptr = ptr + y21 * step;
@ -1617,7 +1617,7 @@ Circle( Mat& img, Point center, int radius, const void* color, int fill )
ICV_HLINE( tptr, x21, x22, color, pix_size ); ICV_HLINE( tptr, x21, x22, color, pix_size );
} }
if( (unsigned)y22 < (unsigned)size.height ) if( y22 >= 0 && y22 < size.height )
{ {
uchar *tptr = ptr + y22 * step; uchar *tptr = ptr + y22 * step;

View File

@ -913,4 +913,12 @@ INSTANTIATE_TEST_CASE_P(
) )
); );
TEST(Drawing, circle_overflow)
{
applyTestTag(CV_TEST_TAG_VERYLONG);
cv::Mat1b matrix = cv::Mat1b::zeros(600, 600);
cv::Scalar kBlue = cv::Scalar(0, 0, 255);
cv::circle(matrix, cv::Point(275, -2147483318), 2147483647, kBlue, 1, 8, 0);
}
}} // namespace }} // namespace