core(test): regression test for 18473
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Sun, 4 Oct 2020 07:11:41 +0000 (07:11 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Mon, 5 Oct 2020 17:14:22 +0000 (17:14 +0000)
modules/core/test/test_mat.cpp

index 43e0078..0bc3961 100644 (file)
@@ -2185,4 +2185,32 @@ TEST(Mat, empty_iterator_16855)
     EXPECT_TRUE(m.begin<uchar>() == m.end<uchar>());
 }
 
+
+TEST(Mat, regression_18473)
+{
+    std::vector<int> sizes(3);
+    sizes[0] = 20;
+    sizes[1] = 50;
+    sizes[2] = 100;
+#if 1  // with the fix
+    std::vector<size_t> steps(2);
+    steps[0] = 50*100*2;
+    steps[1] = 100*2;
+#else  // without the fix
+    std::vector<size_t> steps(3);
+    steps[0] = 50*100*2;
+    steps[1] = 100*2;
+    steps[2] = 2;
+#endif
+    std::vector<short> data(20*50*100, 0);  // 1Mb
+    data[data.size() - 1] = 5;
+
+    // param steps Array of ndims-1 steps
+    Mat m(sizes, CV_16SC1, (void*)data.data(), (const size_t*)steps.data());
+
+    ASSERT_FALSE(m.empty());
+    EXPECT_EQ((int)5, (int)m.at<short>(19, 49, 99));
+}
+
+
 }} // namespace