Skip to content
Permalink
Browse files

Fix crash on corrupt qix files (#2362)

* Fix crash on corrupt qix files (#2362)
  • Loading branch information...
szekerest committed Mar 11, 2019
1 parent 2ab56ae commit 7774a791eb9acfd4f18071c08f454a50b621e0d8
Showing with 10 additions and 4 deletions.
  1. +1 −1 mapshape.c
  2. +7 −1 maptree.c
  3. +1 −1 maptree.h
  4. +1 −1 shptreetst.c
@@ -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);

@@ -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;
@@ -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()");
@@ -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);
@@ -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");

0 comments on commit 7774a79

Please sign in to comment.
You can’t perform that action at this time.