Commit f1dc26d7 authored by LaurentBerger's avatar LaurentBerger Committed by Alexander Alekhin

Merge pull request #13382 from LaurentBerger:imreadsize

* try to solve #13381

* Add note
parent 40a53e3d
...@@ -171,6 +171,8 @@ Currently, the following file formats are supported: ...@@ -171,6 +171,8 @@ Currently, the following file formats are supported:
[Vector](http://www.gdal.org/ogr_formats.html). [Vector](http://www.gdal.org/ogr_formats.html).
- If EXIF information are embedded in the image file, the EXIF orientation will be taken into account - If EXIF information are embedded in the image file, the EXIF orientation will be taken into account
and thus the image will be rotated accordingly except if the flag @ref IMREAD_IGNORE_ORIENTATION is passed. and thus the image will be rotated accordingly except if the flag @ref IMREAD_IGNORE_ORIENTATION is passed.
- By default number of pixels must be less than 2^30. Limit can be set using system
variable OPENCV_IO_MAX_IMAGE_PIXELS
@param filename Name of file to be loaded. @param filename Name of file to be loaded.
@param flags Flag that can take values of cv::ImreadModes @param flags Flag that can take values of cv::ImreadModes
......
...@@ -51,6 +51,8 @@ ...@@ -51,6 +51,8 @@
#undef max #undef max
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <opencv2/core/utils/configuration.private.hpp>
/****************************************************************************************\ /****************************************************************************************\
* Image Codecs * * Image Codecs *
...@@ -58,18 +60,17 @@ ...@@ -58,18 +60,17 @@
namespace cv { namespace cv {
// TODO Add runtime configuration static const size_t CV_IO_MAX_IMAGE_PARAMS = cv::utils::getConfigurationParameterSizeT("OPENCV_IO_MAX_IMAGE_PARAMS", 50);
#define CV_IO_MAX_IMAGE_PARAMS (50) static const size_t CV_IO_MAX_IMAGE_WIDTH = utils::getConfigurationParameterSizeT("OPENCV_IO_MAX_IMAGE_WIDTH", 1 << 20);
#define CV_IO_MAX_IMAGE_WIDTH (1<<20) static const size_t CV_IO_MAX_IMAGE_HEIGHT = utils::getConfigurationParameterSizeT("OPENCV_IO_MAX_IMAGE_HEIGHT", 1 << 20);
#define CV_IO_MAX_IMAGE_HEIGHT (1<<20) static const size_t CV_IO_MAX_IMAGE_PIXELS = utils::getConfigurationParameterSizeT("OPENCV_IO_MAX_IMAGE_PIXELS", 1 << 30);
#define CV_IO_MAX_IMAGE_PIXELS (1<<30) // 1 Gigapixel
static Size validateInputImageSize(const Size& size) static Size validateInputImageSize(const Size& size)
{ {
CV_Assert(size.width > 0); CV_Assert(size.width > 0);
CV_Assert(size.width <= CV_IO_MAX_IMAGE_WIDTH); CV_Assert(static_cast<size_t>(size.width) <= CV_IO_MAX_IMAGE_WIDTH);
CV_Assert(size.height > 0); CV_Assert(size.height > 0);
CV_Assert(size.height <= CV_IO_MAX_IMAGE_HEIGHT); CV_Assert(static_cast<size_t>(size.height) <= CV_IO_MAX_IMAGE_HEIGHT);
uint64 pixels = (uint64)size.width * (uint64)size.height; uint64 pixels = (uint64)size.width * (uint64)size.height;
CV_Assert(pixels <= CV_IO_MAX_IMAGE_PIXELS); CV_Assert(pixels <= CV_IO_MAX_IMAGE_PIXELS);
return size; return size;
...@@ -998,7 +999,7 @@ cvSaveImage( const char* filename, const CvArr* arr, const int* _params ) ...@@ -998,7 +999,7 @@ cvSaveImage( const char* filename, const CvArr* arr, const int* _params )
if( _params ) if( _params )
{ {
for( ; _params[i] > 0; i += 2 ) for( ; _params[i] > 0; i += 2 )
CV_Assert(i < CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons CV_Assert(static_cast<size_t>(i) < cv::CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons
} }
return cv::imwrite_(filename, cv::cvarrToMat(arr), return cv::imwrite_(filename, cv::cvarrToMat(arr),
i > 0 ? std::vector<int>(_params, _params+i) : std::vector<int>(), i > 0 ? std::vector<int>(_params, _params+i) : std::vector<int>(),
...@@ -1029,7 +1030,7 @@ cvEncodeImage( const char* ext, const CvArr* arr, const int* _params ) ...@@ -1029,7 +1030,7 @@ cvEncodeImage( const char* ext, const CvArr* arr, const int* _params )
if( _params ) if( _params )
{ {
for( ; _params[i] > 0; i += 2 ) for( ; _params[i] > 0; i += 2 )
CV_Assert(i < CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons CV_Assert(static_cast<size_t>(i) < cv::CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons
} }
cv::Mat img = cv::cvarrToMat(arr); cv::Mat img = cv::cvarrToMat(arr);
if( CV_IS_IMAGE(arr) && ((const IplImage*)arr)->origin == IPL_ORIGIN_BL ) if( CV_IS_IMAGE(arr) && ((const IplImage*)arr)->origin == IPL_ORIGIN_BL )
......
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