Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#2510 closed defect (fixed)

[PATCH] Fix crashes on corrupted geometries in shapefiles

Reported by: rouault Owned by: sdlime
Priority: normal Milestone: 5.2 release
Component: MapServer C Library Version: svn-trunk (development)
Severity: normal Keywords: shapelib
Cc: warmerdam

Description

This is a clone of a GDAL bug : http://trac.osgeo.org/gdal/ticket/2218.

The attached patch adds checks to msSHPReadPoint and msSHPReadShape so that hostile/corrupted geometries in a shape entity don't cause shapelib to read memory outside of the declared entity size and pabyRec buffer.

I've attached too a zip file containing a few volontary corrupted shapefiles to demonstrate the crashes (or Valgrind errors) and the fix.

Too bad that mapserver doesn't use shapelib 1.2... It duplicates the effort of merging fixes.

Attachments (2)

mapserver_svn_trunk_test2218.zip (4.5 KB ) - added by rouault 16 years ago.
Mapfile and shapefiles demonstrating the bug and the fix
mapserver_svn_trunk_mapshape_fix_crash_on_buggy_shapes.patch (14.4 KB ) - added by rouault 16 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 by sdlime, 16 years ago

Cc: warmerdam added
Status: newassigned

Thanks for the patch! Are there any performance side-effects? Cc'ing Frank for comment...

Steve

comment:2 by rouault, 16 years ago

It shouldn't have too much performance side-effects, as it doesn't change fundamentaly the way shapes are read. However it adds several 'if' for each read, but I don't expect them to be significant in comparison to I/O time.

comment:3 by rouault, 16 years ago

Enclosed a zip file containing a few small good and a few bad simple shapefiles (cf GDAL bug) and a mapfile.

Should crash shp2img on a non-patched mapserver :

./shp2img -m map_test.map -l "goodpoint badpoint goodline badline goodpoly badpoly badpoly2" > test.png

by rouault, 16 years ago

Mapfile and shapefiles demonstrating the bug and the fix

comment:4 by rouault, 16 years ago

I've also updated the patch with a few missing checks in msSHPOpen that have been integreated into shapelib 1.2 some time ago.

comment:5 by warmerdam, 16 years ago

The changes look reasonable to me.

comment:6 by sdlime, 16 years ago

Resolution: fixed
Status: assignedclosed

Patch applied in r7383. Closing...

Steve

comment:7 by sdlime, 16 years ago

Milestone: 5.2 release
Note: See TracTickets for help on using tickets.