Ticket #4090 (closed defect: fixed)
Label size of zero causes divide by zero error
|Reported by:||andystone||Owned by:||tbonfort|
|Component:||MapServer C Library||Version:||6.0|
I was following the tutorial at http://trac.osgeo.org/mapserver/wiki/RenderingOsmDataUbuntu, trying to render open streetmap data with mapserver. I'm using a UK extract of the OSM data.
Everything seemed to be working ok except that once I zoomed in to level 12, some map areas would fail to render. I was initially using the Ubuntu mapserver package, but switched to version 6.0.1 compiled manually to figure out the problem.
After digging through the code, I am fairly sure that the problem occurs because in the example osm-google.map (from mapserver-utils), pedestrian areas have a label size of 0 for zoom level 12 and below. This means that in msAlignText (maplabel.c) you get a calculated spacewidth of zero (if label->space_size_10 is set to a non zero value), which leads to a divide by zero error when calculating nfracspaces around line 240, which in turn leads to a huge value of numspacestoadd and so a call to msSmallMalloc with a huge space request. This call fails and so the map fails to render.
Adding a check for a label size of zero would solve the problem.
Changing the label size to >0 for the pedestrian areas makes the problem go away.
I've marked it as a bug in the mapserver C library, but maybe a label size of 0 isn't allowed, in which case it's mapserver-utils that has the bug.