Commit 7793299e authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #7507 from vrabaud:iplimage_overflow

parents 052e6253 a89aa8c9
...@@ -834,6 +834,9 @@ cvCreateData( CvArr* arr ) ...@@ -834,6 +834,9 @@ cvCreateData( CvArr* arr )
if( !CvIPL.allocateData ) if( !CvIPL.allocateData )
{ {
const int64 imageSize_tmp = (int64)img->widthStep*(int64)img->height;
if( (int64)img->imageSize != imageSize_tmp )
CV_Error( CV_StsNoMem, "Overflow for imageSize" );
img->imageData = img->imageDataOrigin = img->imageData = img->imageDataOrigin =
(char*)cvAlloc( (size_t)img->imageSize ); (char*)cvAlloc( (size_t)img->imageSize );
} }
...@@ -941,7 +944,10 @@ cvSetData( CvArr* arr, void* data, int step ) ...@@ -941,7 +944,10 @@ cvSetData( CvArr* arr, void* data, int step )
img->widthStep = min_step; img->widthStep = min_step;
} }
img->imageSize = img->widthStep * img->height; const int64 imageSize_tmp = (int64)img->widthStep*(int64)img->height;
img->imageSize = (int)imageSize_tmp;
if( (int64)img->imageSize != imageSize_tmp )
CV_Error( CV_StsNoMem, "Overflow for imageSize" );
img->imageData = img->imageDataOrigin = (char*)data; img->imageData = img->imageDataOrigin = (char*)data;
if( (((int)(size_t)data | step) & 7) == 0 && if( (((int)(size_t)data | step) & 7) == 0 &&
...@@ -2958,7 +2964,10 @@ cvInitImageHeader( IplImage * image, CvSize size, int depth, ...@@ -2958,7 +2964,10 @@ cvInitImageHeader( IplImage * image, CvSize size, int depth,
image->widthStep = (((image->width * image->nChannels * image->widthStep = (((image->width * image->nChannels *
(image->depth & ~IPL_DEPTH_SIGN) + 7)/8)+ align - 1) & (~(align - 1)); (image->depth & ~IPL_DEPTH_SIGN) + 7)/8)+ align - 1) & (~(align - 1));
image->origin = origin; image->origin = origin;
image->imageSize = image->widthStep * image->height; const int64 imageSize_tmp = (int64)image->widthStep*(int64)image->height;
image->imageSize = (int)imageSize_tmp;
if( (int64)image->imageSize != imageSize_tmp )
CV_Error( CV_StsNoMem, "Overflow for imageSize" );
return image; return image;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment