opencv_contrib icon indicating copy to clipboard operation
opencv_contrib copied to clipboard

Float overflows when cast to int in get_subbox_chart_physical()

Open y-guyon opened this issue 2 years ago • 0 comments

System information (version)
  • OpenCV => 4.6
  • Operating System / Platform => Linux 64 Bit
  • Compiler => gcc
Detailed description

h may overflow the cast to int in get_subbox_chart_physical():

https://github.com/opencv/opencv_contrib/blob/8eaa8ac1cb4d71ccda65015db4bef0674b2e8ccb/modules/mcc/src/checker_detector.cpp#L1121

It may not SIGILL for you but you can add if (h > INT_MAX) abort(); to detect the issue.

Steps to reproduce

At head (cde1864 / 8eaa8ac1cb4d71ccda65015db4bef0674b2e8ccb) with input https://en.wikipedia.org/wiki/File:Gretag-Macbeth_ColorChecker.jpg:

#include "opencv2/imgcodecs.hpp"
#include "opencv2/mcc.hpp"

int main(int, char**) {
  cv::Mat mat = cv::imread("Gretag-Macbeth_ColorChecker.jpg");
  cv::Ptr<cv::mcc::CCheckerDetector> detector = cv::mcc::CCheckerDetector::create();
  cv::Ptr<cv::mcc::DetectorParameters> params = cv::mcc::DetectorParameters::create();
  params->adaptiveThreshWinSizeMin = 11;
  params->adaptiveThreshWinSizeStep = 4;
  detector->process(mat, cv::mcc::TYPECHART::MCC24, /*nc=*/1, /*use_net=*/false, params);
  return 0;
}
Issue submission checklist
  • [x] I report the issue, it's not a question
  • [x] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • [x] I updated to the latest OpenCV version and the issue is still there
  • [x] There is reproducer code and related data files: videos, images, onnx, etc

y-guyon avatar Aug 08 '22 20:08 y-guyon