From cda88850d1af8cf75ea8ea0c22e23f0cee3e48df Mon Sep 17 00:00:00 2001 From: Uwez Khan Date: Wed, 23 Sep 2026 20:22:10 +0530 Subject: [PATCH] bound obj face vertex index in ptcloud readData --- modules/ptcloud/src/io_obj.cpp | 4 +++- modules/ptcloud/test/test_pointcloud_io.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/ptcloud/src/io_obj.cpp b/modules/ptcloud/src/io_obj.cpp index f95d265420..0db9918bf8 100644 --- a/modules/ptcloud/src/io_obj.cpp +++ b/modules/ptcloud/src/io_obj.cpp @@ -96,7 +96,9 @@ void ObjDecoder::readData(std::vector& points, std::vector& no { auto vertexinfo = split(tokens[i], '/'); std::array idx = { -1, -1, -1 }; - for (int j = 0; j < (int)vertexinfo.size(); j++) + // a face vertex reference holds at most v/vt/vn; ignore any extra + // slash-separated fields instead of writing past idx + for (int j = 0; j < (int)vertexinfo.size() && j < (int)idx.size(); j++) { std::string sj = vertexinfo[j]; // trimming spaces; as a result s can become empty - this is not an error diff --git a/modules/ptcloud/test/test_pointcloud_io.cpp b/modules/ptcloud/test/test_pointcloud_io.cpp index 847de4ad3a..99dcb569bf 100644 --- a/modules/ptcloud/test/test_pointcloud_io.cpp +++ b/modules/ptcloud/test/test_pointcloud_io.cpp @@ -359,4 +359,20 @@ TEST(PointCloud, LoadPlyMalformedElementLine) std::remove(path.c_str()); } +TEST(PointCloud, LoadObjFaceExtraSlashFields) +{ + std::string path = tempfile("extra_slash_face.obj"); + std::ofstream file(path, std::ios::binary); + file << "v 0 0 0\nv 1 0 0\nv 0 1 0\n"; + // a face vertex reference should hold at most v/vt/vn; the extra fields + // used to run past the 3-element index array on the stack + file << "f 1/1/1/9/9/9/9/9/9/9/9/9/9/9/9/9/9/9/9/9\n"; + file.close(); + + std::vector points, normals, rgb; + EXPECT_NO_THROW(cv::loadPointCloud(path, points, normals, rgb)); + EXPECT_EQ(points.size(), size_t(3)); + std::remove(path.c_str()); +} + }} /* namespace opencv_test */