Fixed possible out-of-bound access in circles drawing.

pull/23931/head
Alexander Smorkalov 2 years ago
parent 53af876999
commit 52d9685cb9
  1. 10
      modules/imgproc/src/drawing.cpp
  2. 8
      modules/imgproc/test/test_drawing.cpp

@ -1556,7 +1556,7 @@ Circle( Mat& img, Point center, int radius, const void* color, int fill )
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 )
{
@ -1564,7 +1564,7 @@ Circle( Mat& img, Point center, int radius, const void* color, int fill )
x12 = MIN( x12, size.width - 1 );
}
if( (unsigned)y11 < (unsigned)size.height )
if( y11 >= 0 && y11 < size.height )
{
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 );
}
if( (unsigned)y12 < (unsigned)size.height )
if( y12 >= 0 && y12 < size.height )
{
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 );
}
if( (unsigned)y21 < (unsigned)size.height )
if( y21 >= 0 && y21 < size.height )
{
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 );
}
if( (unsigned)y22 < (unsigned)size.height )
if( y22 >= 0 && y22 < size.height )
{
uchar *tptr = ptr + y22 * step;

@ -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

Loading…
Cancel
Save