Merge pull request #29867 from vrabaud:min_empty

Fix infinite loop in warpAffine
This commit is contained in:
Alexander Smorkalov
2026-09-05 16:39:26 +03:00
committed by GitHub
2 changed files with 32 additions and 0 deletions

View File

@@ -336,6 +336,8 @@ static inline int borderInterpolate_fast( int p, int len, int borderType )
p = p < 0 ? 0 : len - 1;
else if( borderType == BORDER_REFLECT || borderType == BORDER_REFLECT_101 )
{
if( len == 1 )
return 0;
int delta = borderType == BORDER_REFLECT_101;
do
{

View File

@@ -43,6 +43,10 @@
#include "opencv2/ts/ts_gtest.h"
#include "test_precomp.hpp"
#include <chrono>
#include <future>
#include <thread>
namespace opencv_test { namespace {
class CV_ImgWarpBaseTest : public cvtest::ArrayTest
@@ -1199,5 +1203,31 @@ TEST(Imgproc_Warping, DISABLED_playground)
}
}
TEST(Imgproc_Warping, infinite_loop)
{
std::promise<void> promise;
auto future = promise.get_future();
std::thread worker([&promise]() {
cv::Mat src(1, 10, CV_8UC1, cv::Scalar(128));
cv::Mat dst;
cv::Matx23f M(1.f, 0.f, 0.f, 0.f, 1.f, 0.f);
cv::warpAffine(src, dst, M, cv::Size(10, 10), cv::INTER_CUBIC,
cv::BORDER_REFLECT_101);
promise.set_value();
});
auto status = future.wait_for(std::chrono::seconds(1));
if (status == std::future_status::ready) {
worker.join();
} else {
worker.detach();
}
EXPECT_EQ(status, std::future_status::ready)
<< "cv::warpAffine hung in an infinite loop!";
}
}} // namespace
/* End of file. */