summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2024-12-24 20:21:54 +0100
committerAlbert Astals Cid <aacid@kde.org>2024-12-24 20:21:54 +0100
commit26daa2a03963c1ceb5a61d6001815ef0f4b8d21d (patch)
tree81e06ab927382b819facd6ea9a157ab9cc2056b0
parentce8e62996102f43b2b7f6fba4c2f2d644b81f68a (diff)
Splash::gouraudTriangleShadedFill: Check for overflow in some operations
Fixes #1554
-rw-r--r--splash/Splash.cc32
1 files changed, 30 insertions, 2 deletions
diff --git a/splash/Splash.cc b/splash/Splash.cc
index 13cf536e..3d2576a7 100644
--- a/splash/Splash.cc
+++ b/splash/Splash.cc
@@ -5490,8 +5490,36 @@ bool Splash::gouraudTriangleShadedFill(SplashGouraudColor *shading)
// this here is det( T ) == 0
// where T is the matrix to map to barycentric coordinates.
- if ((x[0] - x[2]) * (y[1] - y[2]) - (x[1] - x[2]) * (y[0] - y[2]) == 0) {
- continue; // degenerate triangle.
+ {
+ int x02diff;
+ if (checkedSubtraction(x[0], x[2], &x02diff)) {
+ continue;
+ }
+ int y12diff;
+ if (checkedSubtraction(y[1], y[2], &y12diff)) {
+ continue;
+ }
+ int x12diff;
+ if (checkedSubtraction(x[1], x[2], &x12diff)) {
+ continue;
+ }
+ int y02diff;
+ if (checkedSubtraction(y[0], y[2], &y02diff)) {
+ continue;
+ }
+
+ int x02diffY12diff;
+ if (checkedMultiply(x02diff, y12diff, &x02diffY12diff)) {
+ continue;
+ }
+ int x12diffY02diff;
+ if (checkedMultiply(x12diff, y02diff, &x12diffY02diff)) {
+ continue;
+ }
+
+ if (x02diffY12diff - x12diffY02diff == 0) {
+ continue; // degenerate triangle.
+ }
}
// this here initialises the scanline generation.