Fix #8093: CV_DbgAssert that the result of area() fits in the return value
authorJuha Reunanen <juha.reunanen@tomaattinen.com>
Sun, 29 Jan 2017 15:32:40 +0000 (17:32 +0200)
committerJuha Reunanen <juha.reunanen@tomaattinen.com>
Tue, 31 Jan 2017 13:02:36 +0000 (15:02 +0200)
modules/core/include/opencv2/core/types.hpp

index d5c64ca..13cbe68 100644 (file)
@@ -1592,7 +1592,10 @@ Size_<_Tp>& Size_<_Tp>::operator = (const Size_<_Tp>& sz)
 template<typename _Tp> inline
 _Tp Size_<_Tp>::area() const
 {
-    return width * height;
+    const _Tp result = width * height;
+    CV_DbgAssert(!std::numeric_limits<_Tp>::is_integer
+        || width == 0 || result / width == height); // make sure the result fits in the return value
+    return result;
 }
 
 template<typename _Tp> static inline
@@ -1731,7 +1734,10 @@ Size_<_Tp> Rect_<_Tp>::size() const
 template<typename _Tp> inline
 _Tp Rect_<_Tp>::area() const
 {
-    return width * height;
+    const _Tp result = width * height;
+    CV_DbgAssert(!std::numeric_limits<_Tp>::is_integer
+        || width == 0 || result / width == height); // make sure the result fits in the return value
+    return result;
 }
 
 template<typename _Tp> template<typename _Tp2> inline