Skip to content

Commit 434164f

Browse files
committed
mapshape: check msSHPReadBounds() return value, fix endless loop
With a crafted shapefile, it was possible to put msShapefileWhichShapes() into an extremely long loop, calling msSHPReadBounds() over and over, even if all of those calls fail. This patch adds error checking, and if an error occurs, msShapefileWhichShapes() gives up, because after an I/O error, there is no reasonable chance that anything will ever work properly. Vulnerability found by libFuzzer.
1 parent 6fa2243 commit 434164f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

mapshape.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,10 @@ int msShapefileOpen(shapefileObj *shpfile, const char *mode, const char *filenam
17411741
return -1;
17421742
}
17431743

1744-
msSHPReadBounds( shpfile->hSHP, -1, &(shpfile->bounds));
1744+
if( msSHPReadBounds( shpfile->hSHP, -1, &(shpfile->bounds)) != MS_SUCCESS ) {
1745+
msSHPClose(shpfile->hSHP);
1746+
return -1;
1747+
}
17451748

17461749
bufferSize = strlen(filename)+5;
17471750
dbfFilename = (char *)msSmallMalloc(bufferSize);
@@ -1870,8 +1873,10 @@ int msShapefileWhichShapes(shapefileObj *shpfile, rectObj rect, int debug)
18701873
}
18711874

18721875
for(i=0; i<shpfile->numshapes; i++) {
1873-
if(msSHPReadBounds(shpfile->hSHP, i, &shaperect) == MS_SUCCESS)
1874-
if(msRectOverlap(&shaperect, &rect) == MS_TRUE) msSetBit(shpfile->status, i, 1);
1876+
if(msSHPReadBounds(shpfile->hSHP, i, &shaperect) != MS_SUCCESS)
1877+
return(MS_FAILURE);
1878+
1879+
if(msRectOverlap(&shaperect, &rect) == MS_TRUE) msSetBit(shpfile->status, i, 1);
18751880
}
18761881
}
18771882
}

0 commit comments

Comments
 (0)