Fix UB in CopyMakeConstBoder_8u
authorFederico Martinez <federico.martinez@advertima.com>
Tue, 23 Feb 2021 07:44:17 +0000 (08:44 +0100)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Fri, 26 Feb 2021 19:15:50 +0000 (19:15 +0000)
Caused by overflow of arithmetic operators conversion rank

modules/core/src/copy.cpp

index dcd585d834035bb597919b47a25e02f181530e1c..798fde74d4fe349aef5a2d24d2938d6b2e4c5855 100644 (file)
@@ -1325,13 +1325,12 @@ void copyMakeConstBorder_8u( const uchar* src, size_t srcstep, cv::Size srcroi,
         memcpy( dstInner + srcroi.width, constBuf, right );
     }
 
-    dst += dststep*top;
-
     for( i = 0; i < top; i++ )
-        memcpy(dst + (i - top)*dststep, constBuf, dstroi.width);
+        memcpy(dst + i * dststep, constBuf, dstroi.width);
 
+    dst += (top + srcroi.height) * dststep;
     for( i = 0; i < bottom; i++ )
-        memcpy(dst + (i + srcroi.height)*dststep, constBuf, dstroi.width);
+        memcpy(dst + i * dststep, constBuf, dstroi.width);
 }
 
 }