sw/source/core/layout/frmtool.cxx | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
New commits: commit 0e7fb08f1d2fcc820725b1a73c01dedb69918afd Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Sun Jan 21 16:55:27 2024 +0000 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Sun Jan 21 20:51:47 2024 +0100 ofz#66042 Integer-overflow Change-Id: Id59a725e0839b490e8c0912b2a89fc3cc21931d2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162346 Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx index 45bf3597674b..52f378580a25 100644 --- a/sw/source/core/layout/frmtool.cxx +++ b/sw/source/core/layout/frmtool.cxx @@ -3786,6 +3786,28 @@ void SwFrameHolder::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) } } +static sal_uInt64 CalcCurrentDist(sal_Int64 nDiffX, sal_Int64 nDiffY) +{ + sal_Int64 nDiffX2, nDiffY2; + if (o3tl::checked_multiply(nDiffX, nDiffX, nDiffX2)) + { + SAL_WARN("sw.pageframe", "CalcCurrentDist overflow: X " << nDiffX); + return std::numeric_limits<sal_uInt64>::max(); + } + if (o3tl::checked_multiply(nDiffY, nDiffY, nDiffY2)) + { + SAL_WARN("sw.pageframe", "CalcCurrentDist overflow: Y " << nDiffY); + return std::numeric_limits<sal_uInt64>::max(); + } + sal_uInt64 ret; + if (o3tl::checked_add<sal_uInt64>(nDiffX2, nDiffY2, ret)) + { + SAL_WARN("sw.pageframe", "CalcCurrentDist overflow: " << nDiffX2 << " + " << nDiffY2); + return std::numeric_limits<sal_uInt64>::max(); + } + return ret; +} + SwFrame* GetFrameOfModify(SwRootFrame const*const pLayout, sw::BroadcastingModify const& rMod, SwFrameType const nFrameType, SwPosition const*const pPos, std::pair<Point, bool> const*const pViewPosAndCalcFrame) @@ -3863,7 +3885,7 @@ SwFrame* GetFrameOfModify(SwRootFrame const*const pLayout, sw::BroadcastingModif // Point not in rectangle. Compare distances: const Point aCalcRectCenter = aCalcRect.Center(); const Point aDiff = aCalcRectCenter - pViewPosAndCalcFrame->first; - const sal_uInt64 nCurrentDist = sal_Int64(aDiff.getX()) * sal_Int64(aDiff.getX()) + sal_Int64(aDiff.getY()) * sal_Int64(aDiff.getY()); // opt: no sqrt + const sal_uInt64 nCurrentDist = CalcCurrentDist(aDiff.getX(), aDiff.getY()); if ( !pMinFrame || nCurrentDist < nMinDist ) { pMinFrame = pTmpFrame;