fixed http://code.opencv.org/issues/4276 - set drawing thickness limit to 32767
authorMarek Nogacki <no.marek@gmail.com>
Wed, 13 May 2015 16:54:25 +0000 (18:54 +0200)
committerMarek Nogacki <no.marek@gmail.com>
Wed, 13 May 2015 16:54:25 +0000 (18:54 +0200)
modules/imgproc/src/drawing.cpp

index e8997d3..7f90635 100644 (file)
@@ -45,6 +45,8 @@ namespace cv
 
 enum { XY_SHIFT = 16, XY_ONE = 1 << XY_SHIFT, DRAWING_STORAGE_BLOCK = (1<<12) - 256 };
 
+static const int MAX_THICKNESS = 32767;
+
 struct PolyEdge
 {
     PolyEdge() : y0(0), y1(0), x(0), dx(0), next(0) {}
@@ -1664,7 +1666,7 @@ void line( InputOutputArray _img, Point pt1, Point pt2, const Scalar& color,
     if( line_type == CV_AA && img.depth() != CV_8U )
         line_type = 8;
 
-    CV_Assert( 0 <= thickness );
+    CV_Assert( 0 <= thickness && thickness <= MAX_THICKNESS );
     CV_Assert( 0 <= shift && shift <= XY_SHIFT );
 
     double buf[4];
@@ -1699,6 +1701,7 @@ void rectangle( InputOutputArray _img, Point pt1, Point pt2,
     if( lineType == CV_AA && img.depth() != CV_8U )
         lineType = 8;
 
+    CV_Assert( thickness <= MAX_THICKNESS );
     CV_Assert( 0 <= shift && shift <= XY_SHIFT );
 
     double buf[4];
@@ -1739,7 +1742,8 @@ void circle( InputOutputArray _img, Point center, int radius,
     if( line_type == CV_AA && img.depth() != CV_8U )
         line_type = 8;
 
-    CV_Assert( radius >= 0 && 0 <= shift && shift <= XY_SHIFT );
+    CV_Assert( radius >= 0 && thickness <= MAX_THICKNESS &&
+        0 <= shift && shift <= XY_SHIFT );
 
     double buf[4];
     scalarToRawData(color, buf, img.type(), 0);
@@ -1767,7 +1771,7 @@ void ellipse( InputOutputArray _img, Point center, Size axes,
         line_type = 8;
 
     CV_Assert( axes.width >= 0 && axes.height >= 0 &&
-        0 <= shift && shift <= XY_SHIFT );
+        thickness <= MAX_THICKNESS && 0 <= shift && shift <= XY_SHIFT );
 
     double buf[4];
     scalarToRawData(color, buf, img.type(), 0);
@@ -1792,7 +1796,8 @@ void ellipse(InputOutputArray _img, const RotatedRect& box, const Scalar& color,
     if( lineType == CV_AA && img.depth() != CV_8U )
         lineType = 8;
 
-    CV_Assert( box.size.width >= 0 && box.size.height >= 0 );
+    CV_Assert( box.size.width >= 0 && box.size.height >= 0 &&
+               thickness <= MAX_THICKNESS );
 
     double buf[4];
     scalarToRawData(color, buf, img.type(), 0);
@@ -1854,7 +1859,8 @@ void polylines( Mat& img, const Point* const* pts, const int* npts, int ncontour
         line_type = 8;
 
     CV_Assert( pts && npts && ncontours >= 0 &&
-               0 <= thickness && 0 <= shift && shift <= XY_SHIFT );
+               0 <= thickness && thickness <= MAX_THICKNESS &&
+               0 <= shift && shift <= XY_SHIFT );
 
     double buf[4];
     scalarToRawData( color, buf, img.type(), 0 );
@@ -2374,6 +2380,8 @@ cvDrawContours( void* _img, CvSeq* contour,
     if( !contour )
         return;
 
+    CV_Assert( thickness <= MAX_THICKNESS );
+
     scalarToRawData( externalColor, ext_buf, img.type(), 0 );
     scalarToRawData( holeColor, hole_buf, img.type(), 0 );