mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 21:22:43 -06:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user