Subject: CGAL users discussion list
List archive
- From: jcugnoni <>
- To:
- Subject: [cgal-discuss] Patch to CGAL ImageIO.cpp to prevent overflow
- Date: Mon, 7 Nov 2011 08:39:38 -0800 (PST)
Hello,
I am using CGAL's Surface meshing algorithm for isosurface extraction from
biomedical images.
I discovered a problem using CGAL 3.9: depending on the image I got a
segfault in triLinInterp() in ImageIO.cpp line ~1530. Debugging the code, I
have seen that the crash happens when a very large value of X,Y or Z
coordinate is used. I found out finally that the problem was due to an
integer overflow.
Detailed explanation:
The first part of the function is OK as it works with floating point values:
posx = static_cast<float>(posx /(image->vx));
posy = static_cast<float>(posy /(image->vy));
posz = static_cast<float>(posz /(image->vz));
The faulty part is :
const int i1 = (int)(posz);
const int j1 = (int)(posy);
const int k1 = (int)(posx);
In the case of very large posx,posy or posz (like 1e9 for example), the
pixel coordinate cannot be coded in integer (integer overflow) but the code
does not check for that condition and results in a segfault when evaluating
the voxel values.
I propose to modify the code as follows to avoid this condition:
posx = static_cast<float>(posx /(image->vx));
posy = static_cast<float>(posy /(image->vy));
posz = static_cast<float>(posz /(image->vz));
/// PATCH J.CUGNONI 2011, need to prevent integer overflow for very large
X,Y,Z coords
if(posx > dimx || posy > dimy || posz > dimz)
return value_outside;
/// END PATCH JC
const int i1 = (int)(posz);
const int j1 = (int)(posy);
const int k1 = (int)(posx);
With that addition it runs perfectly!
--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Patch-to-CGAL-ImageIO-cpp-to-prevent-overflow-tp4005022p4005022.html
Sent from the cgal-discuss mailing list archive at Nabble.com.
- [cgal-discuss] Patch to CGAL ImageIO.cpp to prevent overflow, jcugnoni, 11/07/2011
- Re: [cgal-discuss] Patch to CGAL ImageIO.cpp to prevent overflow, Sebastien Loriot (GeometryFactory), 11/10/2011
Archive powered by MHonArc 2.6.16.