From f970f50a9b1a5d849742205889b16f8b1210543f Mon Sep 17 00:00:00 2001 From: Oliver Tan Date: Thu, 7 Oct 2021 20:32:13 +0000 Subject: [PATCH] geo: fix invalid GeoJSON output Release note (bug fix): Fixed a panic that could occur with invalid GeoJSON input using ST_GeomFromGeoJSON/ST_GeogFromGeoJSON. --- pkg/geo/parse.go | 3 +++ pkg/sql/logictest/testdata/logic_test/geospatial | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/pkg/geo/parse.go b/pkg/geo/parse.go index 3e2fed8d791e..073e2397a054 100644 --- a/pkg/geo/parse.go +++ b/pkg/geo/parse.go @@ -115,6 +115,9 @@ func parseGeoJSON( if err := geojson.Unmarshal(b, &t); err != nil { return geopb.SpatialObject{}, err } + if t == nil { + return geopb.SpatialObject{}, errors.Newf("invalid GeoJSON input") + } if defaultSRID != 0 && t.SRID() == 0 { AdjustGeomTSRID(t, defaultSRID) } diff --git a/pkg/sql/logictest/testdata/logic_test/geospatial b/pkg/sql/logictest/testdata/logic_test/geospatial index 9d79389c48bc..1c830ff6c67a 100644 --- a/pkg/sql/logictest/testdata/logic_test/geospatial +++ b/pkg/sql/logictest/testdata/logic_test/geospatial @@ -372,6 +372,12 @@ SELECT ---- true true +statement error invalid GeoJSON input +select st_geomfromgeojson(json_typeof('null')) + +statement error invalid GeoJSON input +select st_geogfromgeojson(json_typeof('null')) + query TTTTTTT SELECT ST_AsText(geom),