From 894b8c36d5719720cbd3bbd2ed3e720bcccb6704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 29 Dec 2011 08:14:37 +0000 Subject: [PATCH] patch to prevent integer overflow --- CGALimageIO/src/CGALImageIO/ImageIO.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CGALimageIO/src/CGALImageIO/ImageIO.cpp b/CGALimageIO/src/CGALImageIO/ImageIO.cpp index c9e79f601c7..d9280151540 100644 --- a/CGALimageIO/src/CGALImageIO/ImageIO.cpp +++ b/CGALimageIO/src/CGALImageIO/ImageIO.cpp @@ -1509,6 +1509,10 @@ float triLinInterp(const _image* image, posy = static_cast(posy /(image->vy)); posz = static_cast(posz /(image->vz)); + //patch suggested by J.Cugnoni to prevent integer overflow + if(posz >= dimz-1 || posy >= dimy-1 || posx >= dimx-1) + return value_outside; + const int i1 = (int)(posz); const int j1 = (int)(posy); const int k1 = (int)(posx); @@ -1517,9 +1521,6 @@ float triLinInterp(const _image* image, const int j2 = j1 + 1; const int k2 = k1 + 1; - if(i2 >= dimz || j2 >= dimy || k2 >= dimx) - return value_outside; - const float KI2 = i2-posz; const float KI1 = posz-i1; const float KJ2 = j2-posy;