From c1cd5dcabed67ce5932879b4c0fc321cd8c305a5 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Wed, 20 Jan 2021 08:35:43 +0100 Subject: Rasterizer: compute intersection factors only when needed Fixes oss-fuzz issue 29285 Change-Id: I8f7e0bc898b119d153a36cef5a74371249ed7686 Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Robert Loehning (cherry picked from commit e1ed570f9d0ec3998f130e2c3870ef49e7994dbf) Reviewed-by: Qt Cherry-pick Bot --- src/gui/painting/qrasterizer.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/gui/painting/qrasterizer.cpp b/src/gui/painting/qrasterizer.cpp index 5a63840c03..48d41f41f0 100644 --- a/src/gui/painting/qrasterizer.cpp +++ b/src/gui/painting/qrasterizer.cpp @@ -657,19 +657,22 @@ static QScFixed intersectPixelFP(int x, QScFixed top, QScFixed bottom, QScFixed QScFixed rightX = IntToQScFixed(x) + QScFixedFactor; QScFixed leftIntersectY, rightIntersectY; - if (slope > 0) { - leftIntersectY = top + QScFixedMultiply(leftX - leftIntersectX, invSlope); - rightIntersectY = leftIntersectY + invSlope; - } else { - leftIntersectY = top + QScFixedMultiply(leftX - rightIntersectX, invSlope); - rightIntersectY = leftIntersectY + invSlope; - } + auto computeIntersectY = [&]() { + if (slope > 0) { + leftIntersectY = top + QScFixedMultiply(leftX - leftIntersectX, invSlope); + rightIntersectY = leftIntersectY + invSlope; + } else { + leftIntersectY = top + QScFixedMultiply(leftX - rightIntersectX, invSlope); + rightIntersectY = leftIntersectY + invSlope; + } + }; if (leftIntersectX >= leftX && rightIntersectX <= rightX) { return QScFixedMultiply(bottom - top, leftIntersectX - leftX + ((rightIntersectX - leftIntersectX) >> 1)); } else if (leftIntersectX >= rightX) { return bottom - top; } else if (leftIntersectX >= leftX) { + computeIntersectY(); if (slope > 0) { return (bottom - top) - QScFixedFastMultiply((rightX - leftIntersectX) >> 1, rightIntersectY - top); } else { @@ -678,12 +681,14 @@ static QScFixed intersectPixelFP(int x, QScFixed top, QScFixed bottom, QScFixed } else if (rightIntersectX <= leftX) { return 0; } else if (rightIntersectX <= rightX) { + computeIntersectY(); if (slope > 0) { return QScFixedFastMultiply((rightIntersectX - leftX) >> 1, bottom - leftIntersectY); } else { return QScFixedFastMultiply((rightIntersectX - leftX) >> 1, leftIntersectY - top); } } else { + computeIntersectY(); if (slope > 0) { return (bottom - rightIntersectY) + ((rightIntersectY - leftIntersectY) >> 1); } else { -- cgit v1.2.3