Ticket #1230 (closed defect: fixed)
crash: PostGIS SQL queries in OGR
| Reported by: | amagnum2@… | Owned by: | mloskot |
|---|---|---|---|
| Priority: | highest | Milestone: | |
| Component: | default | Version: | unspecified |
| Severity: | major | Keywords: | |
| Cc: | amagnum2@… |
Description
If I enter a simple query such as select * from layer, ogr may crash. The bug occurs if the layer has an SRID attched , and does not occur otherwise. When we specify "select * from layer" then the database selects the output format of the geometry -it chooses the PostGIS specific EWKB format as documented in PostGIS documentation http://postgis.refractions.net/docs/ch04.html#id2522847. But when OGR reads the geometry it assumes it is WKB. This can be seen in OGRPGLayer::HEXToGeometry which converts the output from hex to binary and then calls OGRGeometryFactory::createFromWkb. The problem is, that this is not WKB it is EWKB and is formatted differently. OGRGeometryFactory::createFromWkb looks for the size of the linestring in the wrong place , reads the SRID and jumps out of bounds and crashes. If the table does not have SRID, the EWKT is sent without SRID and all is well. As for severity, this bug can be worked around by putting in the field names in the query, and outputting the geometry as WKB or WKT or even EWKT. However, it prevents people from using a simle query such as "select * from layer" if the table has SRID. I don't see a simple solution to this one, since EWKB is not a standard format and it may not be worthwhile to support it in OGR for all geometries. Sadly I could find a way to make PostGIS output the geometry column in WKB which would also solve the problem. My testing environment is the latsest PGSQL and PostGIS e.g. 8.1.4 and 1.1.3 with GDAL 1.3.2.0 from FWtools as well as a CVS snaphsot from 6/6/2006
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

