Fix overlow pointers.

`step` and `maskStep` are used to increase/decrease `pImage`.
But it's done on unsigned type, relying on overflow, which is UB.
(step is size_t but seed.y is int and can be negative, the result
is therefore unsigned which can overflow)
This commit is contained in:
Vincent Rabaud 2025-01-27 09:58:07 +01:00
parent df5da4abcd
commit c5f6ed6fef

View File

@ -283,7 +283,7 @@ floodFillGrad_CnIR( Mat& image, Mat& msk,
Diff diff, ConnectedComp* region, int flags,
std::vector<FFillSegment>* buffer )
{
size_t step = image.step, maskStep = msk.step;
auto step = static_cast<std::ptrdiff_t>(image.step), maskStep = static_cast<std::ptrdiff_t>(msk.step);
uchar* pImage = image.ptr();
_Tp* img = (_Tp*)(pImage + step*seed.y);
uchar* pMask = msk.ptr() + maskStep + sizeof(_MTp);