Skip to content

cv::rectangle with very large cv::Rect triggers undefined behavior sanitizer #21037

@vrabaud

Description

@vrabaud
System information (version)
  • OpenCV => 4.5.4
  • Operating System / Platform => Linux
  • Compiler => clang 12
Detailed description

cv::rectangle with a cv::Rect where x and width are std::numeric_limits::max() creates a problem because it calls Rect::br() which overflows (x+width does not fit in an int and overflows).
The external call to cv::rectangle is still valid, the internal call to cv::Rect::br() not. What should be the proper solution ?

  • not allow the creation of a cv::Rect with such big values because br() (and area() ) will overflow ?
  • only warn of overflows when calling br() ?
  • have br() return std::numeric_limits::max() ? (probably not desirable because inaccurate, then again what is returned now is wrong)
  • create a safe_br() function that caps and not overflows ?
  • only fix cv::rectangle for now. Then again, other functions will probably fail.
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions