Skip to content

Commit

Permalink
Fix crash on corrupt qix files (#2362)
Browse files Browse the repository at this point in the history
* Fix crash on corrupt qix files (#2362)
  • Loading branch information
szekerest committed Mar 11, 2019
1 parent 2ab56ae commit 7774a79
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mapshape.c
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ int msShapefileWhichShapes(shapefileObj *shpfile, rectObj rect, int debug)

sprintf(filename, "%s%s", sourcename, MS_INDEX_EXTENSION);

shpfile->status = msSearchDiskTree(filename, rect, debug);
shpfile->status = msSearchDiskTree(filename, rect, debug, shpfile->numshapes);
free(filename);
free(sourcename);

Expand Down
8 changes: 7 additions & 1 deletion maptree.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ static void searchDiskTreeNode(SHPTreeHandle disktree, rectObj aoi, ms_bitarray
return;
}

ms_bitarray msSearchDiskTree(const char *filename, rectObj aoi, int debug)
ms_bitarray msSearchDiskTree(const char *filename, rectObj aoi, int debug, int numshapes)
{
SHPTreeHandle disktree;
ms_bitarray status=NULL;
Expand All @@ -541,6 +541,12 @@ ms_bitarray msSearchDiskTree(const char *filename, rectObj aoi, int debug)
return(NULL);
}

if (disktree->nShapes != numshapes) {
msSetError(MS_SHPERR, "The spatial index file %s is corrupt.", "msSearchDiskTree()", filename);
msSHPDiskTreeClose(disktree);
return(NULL);
}

status = msAllocBitArray(disktree->nShapes);
if(!status) {
msSetError(MS_MEMERR, NULL, "msSearchDiskTree()");
Expand Down
2 changes: 1 addition & 1 deletion maptree.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extern "C" {
MS_DLL_EXPORT void msDestroyTree(treeObj *tree);

MS_DLL_EXPORT ms_bitarray msSearchTree(const treeObj *tree, rectObj aoi);
MS_DLL_EXPORT ms_bitarray msSearchDiskTree(const char *filename, rectObj aoi, int debug);
MS_DLL_EXPORT ms_bitarray msSearchDiskTree(const char *filename, rectObj aoi, int debug, int numshapes);

MS_DLL_EXPORT treeObj *msReadTree(char *filename, int debug);
MS_DLL_EXPORT int msWriteTree(treeObj *tree, char *filename, int LSB_order);
Expand Down
2 changes: 1 addition & 1 deletion shptreetst.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int main( int argc, char ** argv )
rect.maxy = node->rect.maxy;
}

bitmap = msSearchDiskTree( argv[1], rect, 0 /* no debug*/ );
bitmap = msSearchDiskTree( argv[1], rect, 0 /* no debug*/, j );

if ( bitmap ) {
printf ("result of rectangle search was \n");
Expand Down

0 comments on commit 7774a79

Please sign in to comment.