Merge pull request #30053 from uwezkhan:obj-face-index-bound

ptcloud: bound obj face vertex index in ObjDecoder readData 🤖🤖🤖
This commit is contained in:
Alexander Smorkalov
2026-09-24 09:19:49 +03:00
committed by GitHub
2 changed files with 19 additions and 1 deletions
+3 -1
View File
@@ -96,7 +96,9 @@ void ObjDecoder::readData(std::vector<Point3f>& points, std::vector<Point3f>& no
{
auto vertexinfo = split(tokens[i], '/');
std::array<int, 3> 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
@@ -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<cv::Point3f> 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 */