diff --git a/libheif/security_limits.cc b/libheif/security_limits.cc index 56b03a6450..bba4bb8517 100644 --- a/libheif/security_limits.cc +++ b/libheif/security_limits.cc @@ -56,16 +56,18 @@ Error check_for_valid_image_size(const heif_security_limits* limits, uint32_t wi // --- check whether the image size is "too large" - auto max_width_height = static_cast(std::numeric_limits::max()); - if ((width > max_width_height || height > max_width_height) || - (height != 0 && width > maximum_image_size_limit / height)) { - std::stringstream sstr; - sstr << "Image size " << width << "x" << height << " exceeds the maximum image size " - << maximum_image_size_limit << "\n"; - - return {heif_error_Memory_allocation_error, - heif_suberror_Security_limit_exceeded, - sstr.str()}; + if (maximum_image_size_limit > 0) { + auto max_width_height = static_cast(std::numeric_limits::max()); + if ((width > max_width_height || height > max_width_height) || + (height != 0 && width > maximum_image_size_limit / height)) { + std::stringstream sstr; + sstr << "Image size " << width << "x" << height << " exceeds the maximum image size " + << maximum_image_size_limit << "\n"; + + return {heif_error_Memory_allocation_error, + heif_suberror_Security_limit_exceeded, + sstr.str()}; + } } if (width == 0 || height == 0) {