Skip to content

try to solve #13381 - #13382

Merged
alalek merged 2 commits into
opencv:3.4from
LaurentBerger:imreadsize
Dec 9, 2018
Merged

alalek merged 2 commits into
opencv:3.4from
LaurentBerger:imreadsize

Conversation

@LaurentBerger

@LaurentBerger LaurentBerger commented Dec 6, 2018 •

Copy link
Copy Markdown
Contributor

resolves #13381

// TODO Add runtime configuration
#define CV_IO_MAX_IMAGE_PARAMS (50)
#define CV_IO_MAX_IMAGE_WIDTH (1<<20)
#define CV_IO_MAX_IMAGE_HEIGHT (1<<20)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove "TODO" comment too and perform reading of these options once (example, but probably inside of validateInputImageSize() function).

Comment thread modules/imgcodecs/src/loadsave.cpp Outdated
uint64 pixels = (uint64)size.width * (uint64)size.height;
CV_Assert(pixels <= CV_IO_MAX_IMAGE_PIXELS);
uint64 minSizeFile = utils::getConfigurationParameterSizeT("OPENCV_IO_MAX_IMAGE_WIDTH", 1 << 20)*utils::getConfigurationParameterSizeT("OPENCV_IO_MAX_IMAGE_HEIGHT", 1 << 20);
CV_Assert(pixels <= utils::getConfigurationParameterSizeT("OPENCV_IO_MAX_IMAGE_PIXELS", std::min<size_t>(minSizeFile, std::numeric_limits<std::size_t>::max()>>2)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. minSizeFile is not needed. Max width, max height and max total number of pixels should stay different. Nobody want to allocate 128Gb on server due malformed input image.

  2. std::numeric_limits<std::size_t>::max()>>2 - this threshold is very huge, so please keep defaults the same.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@LaurentBerger

Copy link
Copy Markdown
Contributor Author

Finally if I don't change CV_IO_MAX_IMAGE_PIXELS (1<<30) exception still occurs then can we change in 1<<31 ?

@alalek

alalek commented Dec 8, 2018

Copy link
Copy Markdown
Member

@LaurentBerger Right. This behavior is expected. There is another description of the problem: #8511

@LaurentBerger

Copy link
Copy Markdown
Contributor Author

Sorry my idea is bad. I don't change default value and I add a note in imread doc :

By default number of pixels must be less than 2^30. Limit can be set using system variable OPENCV_IO_MAX_IMAGE_PIXELS

@alalek alalek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! Thank you 👍

@alalek

alalek commented Dec 8, 2018

Copy link
Copy Markdown
Member

Documentation note 👍

@alalek
alalek merged commit f1dc26d into opencv:3.4 Dec 9, 2018
@alalek alalek mentioned this pull request Dec 9, 2018
@LaurentBerger
LaurentBerger deleted the imreadsize branch December 9, 2018 16:47
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants