[gdal-dev] Shapefile with corrupted index: SHAPE_RESTORE_SHX=YES doesn't correctly repairs it.

Andrea Giudiceandrea andreaerdna at libero.it
Tue May 16 04:41:05 PDT 2023


Il 15/05/2023 15:34, Andrea Giudiceandrea ha scritto:
> it seems to me ogr fails to properly create the .idx [EDIT: .shx] file: 
> it incorrectly stores, in the index file header, the total length in 
> 16-bit words of the .shp file instead of the total length in 16-bit 
> words of the .idx [EDIT: .shx] file itself.

Looking at the code, SHPRestoreSHX initially copies the SHP header 
(including the SHP content length) to the SHX file and then it doesn't 
updates the SHX content length in the SHX header when an error occurred 
during the reading of the SHP file.

I propose the PR https://github.com/OSGeo/gdal/pull/7774 in order to 
update the SHX content length even if an error occurred.

Maybe would it be better to let SHPRestoreSHX modify the SHX file (when 
already present) only at the end of the SHP reading procedure and only 
if no error occurred?

Best regards.

Andrea Giudiceandrea


More information about the gdal-dev mailing list