Opened 10 years ago

Closed 10 years ago

#3827 closed defect (fixed)

segfault on null point coordinates in ogr geojson driver

Reported by: springmeyer Owned by: warmerdam
Priority: normal Milestone: 1.8.0
Component: OGR_SF Version: unspecified
Severity: normal Keywords:
Cc:

Description

Running into segfaults in Mapnik reading json from couchdb, traced back to ogr geojson driver which appears to crash at initial parsing of the geojson:

0   libgdal.1.dylib               	0x0000000103a5b404 json_object_get_type + 4
1   libgdal.1.dylib               	0x0000000103ae88f2 OGRGeoJSONReadRawPoint(json_object*, OGRPoint&) + 146
2   libgdal.1.dylib               	0x0000000103ae9540 OGRGeoJSONReadPoint(json_object*) + 176
3   libgdal.1.dylib               	0x0000000103ae9f9e OGRGeoJSONReadGeometry(json_object*) + 270
4   libgdal.1.dylib               	0x0000000103aea20b OGRGeoJSONReader::ReadGeometry(json_object*) + 27
5   libgdal.1.dylib               	0x0000000103aea42d OGRGeoJSONReader::ReadFeature(json_object*) + 429
6   libgdal.1.dylib               	0x0000000103aea6d0 OGRGeoJSONReader::ReadFeatureCollection(json_object*) + 224
7   libgdal.1.dylib               	0x0000000103aea7b3 OGRGeoJSONReader::ReadLayer(char const*, OGRGeoJSONDataSource*) + 179
8   libgdal.1.dylib               	0x0000000103ae6f85 OGRGeoJSONDataSource::LoadLayer() + 149
9   libgdal.1.dylib               	0x0000000103ae75ae OGRGeoJSONDataSource::Open(char const*) + 110
10  libgdal.1.dylib               	0x0000000103ae7a11 OGRGeoJSONDriver::Open(char const*, int, char**) + 161
11  libgdal.1.dylib               	0x0000000103b04c83 OGRSFDriverRegistrar::Open(char const*, int, OGRSFDriver**) + 195
12  ogr.input                     	0x000000010402164e ogr_datasource::bind() const + 94
13  ogr.input                     	0x0000000104023554 ogr_datasource::ogr_datasource(mapnik::parameters const&, bool) + 1940
14  ogr.input                     	0x00000001040239f3 create + 51
15  libmapnik2.dylib              	0x0000000101a68d63 mapnik::datasource_cache::create(mapnik::parameters const&, bool) + 1427

Looking through geojson I see:

{
    "type": "FeatureCollection", 
    "features": [
         {
            "geometry": {
                "type": "Point", 
                "coordinates": [
                    null, 
                    null
                ]
            }, 
            "type": "Feature", 
            "properties": {
                "foo": 1, 
             }
        }, 
    ]
}

Digging into ogr noticed the work in r19505, but it appears it did not test enough null cases.

After rebuilding trunk I still get segfaults trying to run ogrinfo on that 'ogr_geojson_14.geojson'.

But, the attached patch seems to fix things.

Attachments (1)

avoid_segfault_on_null_point_coords.diff (2.3 KB) - added by springmeyer 10 years ago.
Patch to fix segfaulting ogr geojson driver on null point coordinates

Download all attachments as: .zip

Change History (3)

Changed 10 years ago by springmeyer

Patch to fix segfaulting ogr geojson driver on null point coordinates

comment:1 Changed 10 years ago by springmeyer

Also, gdal autotest should ideally add these cases:

  • ogr_geojson_14.geojson

     
    55,
    66{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [null] } }
    77,
     8{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [null,1] } }
     9,
     10{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [1,null] } }
     11,
     12{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [null,null] } }
     13,
    814{ "type": "Feature", "properties": { }, "geometry": { "type": "LineString", "coordinates": null } }
    915,
    1016{ "type": "Feature", "properties": { }, "geometry": { "type": "LineString", "coordinates": [ null ] } }

comment:2 Changed 10 years ago by Even Rouault

Component: defaultOGR_SF
Milestone: 1.8.0
Resolution: fixed
Status: newclosed

Thanks. Patch slightly modified to remove debugging trace and return false instead of NULL.

Fixed in r21107. Test enhanced in r21108

Note: See TracTickets for help on using tickets.