ptcloud: bound triangle vertex indices in triangleRasterize 🤖🤖🤖 (#30640)

* ptcloud: bound triangle vertex indices in triangleRasterize

* ptcloud: use checkRange for the triangle index check
This commit is contained in:
uwezkhan
2026-11-24 19:11:50 +05:30
committed by GitHub
parent 3e3f338dde
commit 06f7ecb5ce
2 changed files with 52 additions and 2 deletions

View File

@@ -229,6 +229,15 @@ static void triangleRasterizeInternal(InputArray _vertices, InputArray _indices,
triangles = triangles.reshape(3, 1).t();
nTriangles = (int)triangles.total();
// indices are used to read vertices and colors, check them all before anything is drawn
Mat flatIndices = triangles.reshape(1);
Point badPos;
if (!checkRange(flatIndices, true, &badPos, 0, nVerts))
{
CV_Error(Error::StsOutOfRange, cv::format("Triangle %d has vertex index %d, expected [0, %d)",
badPos.y, flatIndices.at<int>(badPos), nVerts));
}
if (!_colors.empty())
{
int colorType = _colors.type();
@@ -308,8 +317,6 @@ static void triangleRasterizeInternal(InputArray _vertices, InputArray _indices,
for (int i = 0; i < 3; i++)
{
int idx = tri[i];
CV_DbgAssert(idx >= 0 && idx < nVerts);
col[i] = colors.empty() ? Vec3f::all(0) : colors.at<Vec3f>(idx);
ver[i] = screenVertices.at<Vec4f>(idx);
}