Bug#976144: librttopo1: buggy/missing geojson support

Roman Kurakin roma_rik at mail.ru
Mon Nov 30 12:31:26 GMT 2020


Package: librttopo1
Version: 1.1.0-2+1
Severity: important
Tags: patch upstream

Since librttopo is suggested as a replacement for liblwgeom, and the part of it
functionality is missing (switched off by ifdef) the bug becomes critical.

Functionality is switched off due to missing code in configure.  Looks like it
was lost while fork from original liblwgeom (part of postgis project).

All of the versions currently in debian are affected by this problem.



-- System Information:
Debian Release: 10.6
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.19.0-9-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US:en (charmap=UTF-8)
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages librttopo1 depends on:
ii  libc6         2.28-10
ii  libgeos-c1v5  3.7.1-1

librttopo1 recommends no packages.

librttopo1 suggests no packages.

-- no debconf information
-------------- next part --------------
Index: librttopo-1.1.0/configure.ac
===================================================================
--- librttopo-1.1.0.orig/configure.ac
+++ librttopo-1.1.0/configure.ac
@@ -131,6 +131,67 @@ RTGEOM_GEOS_VERSION="$GEOS_MAJOR_VERSION
 AC_DEFINE_UNQUOTED([RTGEOM_GEOS_VERSION], [$RTGEOM_GEOS_VERSION], [GEOS library version])
 AC_SUBST([RTGEOM_GEOS_VERSION])
 
+# ===========================================================================
+# Detect if json-c installed
+# ===========================================================================
+
+CHECK_JSON=yes
+HAVE_JSON=no
+HAVE_JSON_C=no
+
+AC_ARG_WITH([json],
+	[AS_HELP_STRING([--without-json], [build without json-c support])],
+	[CHECK_JSON="$withval"], [])
+
+if test "$CHECK_JSON" != "no"; then
+
+AC_ARG_WITH([jsondir],
+	[AS_HELP_STRING([--with-jsondir=PATH], [specify the json-c installation directory])],
+	[JSONDIR="$withval"], [JSONDIR=])
+
+if test ! "x$JSONDIR" = "x"; then
+	# Make sure that the directory exists
+	if test "x$JSONDIR" = "xyes"; then
+		AC_MSG_ERROR([you must specify a parameter to --with-jsondir, e.g. --with-jsondir=/path/to])
+	else
+		AC_MSG_RESULT([Using user-specified json-c directory: $JSONDIR])
+
+		# Add the include directory to JSON_CPPFLAGS
+		JSON_CPPFLAGS="-I$JSONDIR/include"
+		JSON_LDFLAGS="-L$JSONDIR/lib"
+	fi
+fi
+
+# Check that we can find the json/json.h header file
+CPPFLAGS_SAVE="$CPPFLAGS"
+CPPFLAGS="$JSON_CPPFLAGS"
+AC_CHECK_HEADER([json/json.h], [HAVE_JSON=yes], [
+  AC_CHECK_HEADER([json-c/json.h], [HAVE_JSON=yes; HAVE_JSON_C=yes], [])
+])
+CPPFLAGS="$CPPFLAGS_SAVE"
+
+# Ensure we can link against libjson
+LIBS_SAVE="$LIBS"
+LIBS="$JSON_LDFLAGS"
+AC_CHECK_LIB([json-c], [json_object_get], [HAVE_JSON=yes; JSON_LDFLAGS="${JSON_LDFLAGS} -ljson-c"], [
+  AC_CHECK_LIB([json], [json_object_get], [HAVE_JSON=yes; JSON_LDFLAGS="${JSON_LDFLAGS} -ljson"], [], [])
+], [])
+LIBS="$LIBS_SAVE"
+
+if test "$HAVE_JSON" = "yes"; then
+	AC_DEFINE([HAVE_LIBJSON], 1, [Define to 1 if libjson is present])
+fi
+if test "$HAVE_JSON_C" = "yes"; then
+	AC_DEFINE([HAVE_LIBJSON_C], 1, [Define to 1 if libjson resides in a json-c subdir])
+fi
+
+AC_SUBST([JSON_CPPFLAGS])
+AC_SUBST([JSON_LDFLAGS])
+AC_SUBST([HAVE_JSON])
+
+fi
+
+
 # SRID stuff
 SRID_MAX=999999
 SRID_USR_MAX=998999
Index: librttopo-1.1.0/src/rtin_geojson.c
===================================================================
--- librttopo-1.1.0.orig/src/rtin_geojson.c
+++ librttopo-1.1.0/src/rtin_geojson.c
@@ -47,17 +47,17 @@
 
 #include <string.h>
 
-static void geojson_rterror(char *msg, int error_code)
+static void geojson_rterror(const RTCTX *ctx, char *msg, int error_code)
 {
   RTDEBUGF(ctx, 3, "rtgeom_from_geojson ERROR %i", error_code);
   rterror(ctx, "%s", msg);
 }
 
 /* Prototype */
-static RTGEOM* parse_geojson(json_object *geojson, int *hasz, int root_srid);
+static RTGEOM* parse_geojson(const RTCTX *ctx, json_object *geojson, int *hasz, int root_srid);
 
 static json_object*
-findMemberByName(json_object* poObj, const char* pszName )
+findMemberByName(const RTCTX *ctx, json_object* poObj, const char* pszName )
 {
   json_object* poTmp;
   json_object_iter it;
@@ -75,7 +75,7 @@ findMemberByName(json_object* poObj, con
   {
     if( NULL == json_object_get_object(poTmp)->head )
     {
-      geojson_rterror("invalid GeoJSON representation", 2);
+      geojson_rterror(ctx, "invalid GeoJSON representation", 2);
       return NULL;
     }
 
@@ -95,7 +95,7 @@ findMemberByName(json_object* poObj, con
 
 
 static int
-parse_geojson_coord(json_object *poObj, int *hasz, RTPOINTARRAY *pa)
+parse_geojson_coord(const RTCTX *ctx, json_object *poObj, int *hasz, RTPOINTARRAY *pa)
 {
   RTPOINT4D pt;
 
@@ -110,7 +110,7 @@ parse_geojson_coord(json_object *poObj,
 
     if ( nSize < 2 )
     {
-      geojson_rterror("Too few ordinates in GeoJSON", 4);
+      geojson_rterror(ctx, "Too few ordinates in GeoJSON", 4);
       return RT_FAILURE;
     }
 
@@ -158,7 +158,7 @@ parse_geojson_coord(json_object *poObj,
 }
 
 static RTGEOM*
-parse_geojson_point(json_object *geojson, int *hasz, int root_srid)
+parse_geojson_point(const RTCTX *ctx, json_object *geojson, int *hasz, int root_srid)
 {
   RTGEOM *geom;
   RTPOINTARRAY *pa;
@@ -166,15 +166,15 @@ parse_geojson_point(json_object *geojson
 
   RTDEBUGF(ctx, 3, "parse_geojson_point called with root_srid = %d.", root_srid );
 
-  coords = findMemberByName( geojson, "coordinates" );
+  coords = findMemberByName( ctx, geojson, "coordinates" );
   if ( ! coords )
   {
-    geojson_rterror("Unable to find 'coordinates' in GeoJSON string", 4);
+    geojson_rterror(ctx, "Unable to find 'coordinates' in GeoJSON string", 4);
     return NULL;
   }
 
   pa = ptarray_construct_empty(ctx, 1, 0, 1);
-  parse_geojson_coord(coords, hasz, pa);
+  parse_geojson_coord(ctx, coords, hasz, pa);
 
   geom = (RTGEOM *) rtpoint_construct(ctx, root_srid, NULL, pa);
   RTDEBUG(ctx, 2, "parse_geojson_point finished.");
@@ -182,7 +182,7 @@ parse_geojson_point(json_object *geojson
 }
 
 static RTGEOM*
-parse_geojson_linestring(json_object *geojson, int *hasz, int root_srid)
+parse_geojson_linestring(const RTCTX *ctx, json_object *geojson, int *hasz, int root_srid)
 {
   RTGEOM *geom;
   RTPOINTARRAY *pa;
@@ -191,10 +191,10 @@ parse_geojson_linestring(json_object *ge
 
   RTDEBUG(ctx, 2, "parse_geojson_linestring called.");
 
-  points = findMemberByName( geojson, "coordinates" );
+  points = findMemberByName( ctx, geojson, "coordinates" );
   if ( ! points )
   {
-    geojson_rterror("Unable to find 'coordinates' in GeoJSON string", 4);
+    geojson_rterror(ctx, "Unable to find 'coordinates' in GeoJSON string", 4);
   return NULL;
   }
 
@@ -207,7 +207,7 @@ parse_geojson_linestring(json_object *ge
     {
       json_object* coords = NULL;
       coords = json_object_array_get_idx( points, i );
-      parse_geojson_coord(coords, hasz, pa);
+      parse_geojson_coord(ctx, coords, hasz, pa);
     }
   }
 
@@ -218,7 +218,7 @@ parse_geojson_linestring(json_object *ge
 }
 
 static RTGEOM*
-parse_geojson_polygon(json_object *geojson, int *hasz, int root_srid)
+parse_geojson_polygon(const RTCTX *ctx, json_object *geojson, int *hasz, int root_srid)
 {
   RTPOINTARRAY **ppa = NULL;
   json_object* rings = NULL;
@@ -226,16 +226,16 @@ parse_geojson_polygon(json_object *geojs
   int i = 0, j = 0;
   int nRings = 0, nPoints = 0;
 
-  rings = findMemberByName( geojson, "coordinates" );
+  rings = findMemberByName( ctx, geojson, "coordinates" );
   if ( ! rings )
   {
-    geojson_rterror("Unable to find 'coordinates' in GeoJSON string", 4);
+    geojson_rterror(ctx, "Unable to find 'coordinates' in GeoJSON string", 4);
     return NULL;
   }
 
   if ( json_type_array != json_object_get_type(rings) )
   {
-    geojson_rterror("The 'coordinates' in GeoJSON are not an array", 4);
+    geojson_rterror(ctx, "The 'coordinates' in GeoJSON are not an array", 4);
     return NULL;
   }
 
@@ -252,7 +252,7 @@ parse_geojson_polygon(json_object *geojs
     points = json_object_array_get_idx(rings, i);
     if ( ! points || json_object_get_type(points) != json_type_array )
     {
-      geojson_rterror("The 'coordinates' in GeoJSON ring are not an array", 4);
+      geojson_rterror(ctx, "The 'coordinates' in GeoJSON ring are not an array", 4);
       return NULL;
     }
     nPoints = json_object_array_length(points);
@@ -268,7 +268,7 @@ parse_geojson_polygon(json_object *geojs
     {
       json_object* coords = NULL;
       coords = json_object_array_get_idx( points, j );
-      parse_geojson_coord(coords, hasz, ppa[i]);
+      parse_geojson_coord(ctx, coords, hasz, ppa[i]);
     }
   }
 
@@ -280,7 +280,7 @@ parse_geojson_polygon(json_object *geojs
 }
 
 static RTGEOM*
-parse_geojson_multipoint(json_object *geojson, int *hasz, int root_srid)
+parse_geojson_multipoint(const RTCTX *ctx, json_object *geojson, int *hasz, int root_srid)
 {
   RTGEOM *geom;
   int i = 0;
@@ -295,10 +295,10 @@ parse_geojson_multipoint(json_object *ge
     geom = (RTGEOM *)rtcollection_construct_empty(ctx, RTMULTIPOINTTYPE, -1, 1, 0);
   }
 
-  poObjPoints = findMemberByName( geojson, "coordinates" );
+  poObjPoints = findMemberByName( ctx, geojson, "coordinates" );
   if ( ! poObjPoints )
   {
-    geojson_rterror("Unable to find 'coordinates' in GeoJSON string", 4);
+    geojson_rterror(ctx, "Unable to find 'coordinates' in GeoJSON string", 4);
     return NULL;
   }
 
@@ -312,7 +312,7 @@ parse_geojson_multipoint(json_object *ge
       poObjCoords = json_object_array_get_idx( poObjPoints, i );
 
       pa = ptarray_construct_empty(ctx, 1, 0, 1);
-      parse_geojson_coord(poObjCoords, hasz, pa);
+      parse_geojson_coord(ctx, poObjCoords, hasz, pa);
 
       geom = (RTGEOM*)rtmpoint_add_rtpoint(ctx, (RTMPOINT*)geom,
                                            (RTPOINT*)rtpoint_construct(ctx, root_srid, NULL, pa));
@@ -323,7 +323,7 @@ parse_geojson_multipoint(json_object *ge
 }
 
 static RTGEOM*
-parse_geojson_multilinestring(json_object *geojson, int *hasz, int root_srid)
+parse_geojson_multilinestring(const RTCTX *ctx, json_object *geojson, int *hasz, int root_srid)
 {
   RTGEOM *geom = NULL;
   int i, j;
@@ -338,10 +338,10 @@ parse_geojson_multilinestring(json_objec
     geom = (RTGEOM *)rtcollection_construct_empty(ctx, RTMULTILINETYPE, -1, 1, 0);
   }
 
-  poObjLines = findMemberByName( geojson, "coordinates" );
+  poObjLines = findMemberByName( ctx, geojson, "coordinates" );
   if ( ! poObjLines )
   {
-    geojson_rterror("Unable to find 'coordinates' in GeoJSON string", 4);
+    geojson_rterror(ctx, "Unable to find 'coordinates' in GeoJSON string", 4);
     return NULL;
   }
 
@@ -362,7 +362,7 @@ parse_geojson_multilinestring(json_objec
         {
           json_object* coords = NULL;
           coords = json_object_array_get_idx( poObjLine, j );
-          parse_geojson_coord(coords, hasz, pa);
+          parse_geojson_coord(ctx, coords, hasz, pa);
         }
 
         geom = (RTGEOM*)rtmline_add_rtline(ctx, (RTMLINE*)geom,
@@ -375,7 +375,7 @@ parse_geojson_multilinestring(json_objec
 }
 
 static RTGEOM*
-parse_geojson_multipolygon(json_object *geojson, int *hasz, int root_srid)
+parse_geojson_multipolygon(const RTCTX *ctx, json_object *geojson, int *hasz, int root_srid)
 {
   RTGEOM *geom = NULL;
   int i, j, k;
@@ -390,10 +390,10 @@ parse_geojson_multipolygon(json_object *
     geom = (RTGEOM *)rtcollection_construct_empty(ctx, RTMULTIPOLYGONTYPE, -1, 1, 0);
   }
 
-  poObjPolys = findMemberByName( geojson, "coordinates" );
+  poObjPolys = findMemberByName( ctx, geojson, "coordinates" );
   if ( ! poObjPolys )
   {
-    geojson_rterror("Unable to find 'coordinates' in GeoJSON string", 4);
+    geojson_rterror(ctx, "Unable to find 'coordinates' in GeoJSON string", 4);
     return NULL;
   }
 
@@ -423,7 +423,7 @@ parse_geojson_multipolygon(json_object *
             for ( k=0; k < nPoints; k++ )
             {
               json_object* coords = json_object_array_get_idx( points, k );
-              parse_geojson_coord(coords, hasz, pa);
+              parse_geojson_coord(ctx, coords, hasz, pa);
             }
 
             rtpoly_add_ring(ctx, rtpoly, pa);
@@ -438,7 +438,7 @@ parse_geojson_multipolygon(json_object *
 }
 
 static RTGEOM*
-parse_geojson_geometrycollection(json_object *geojson, int *hasz, int root_srid)
+parse_geojson_geometrycollection(const RTCTX *ctx, json_object *geojson, int *hasz, int root_srid)
 {
   RTGEOM *geom = NULL;
   int i;
@@ -453,10 +453,10 @@ parse_geojson_geometrycollection(json_ob
     geom = (RTGEOM *)rtcollection_construct_empty(ctx, RTCOLLECTIONTYPE, -1, 1, 0);
   }
 
-  poObjGeoms = findMemberByName( geojson, "geometries" );
+  poObjGeoms = findMemberByName( ctx, geojson, "geometries" );
   if ( ! poObjGeoms )
   {
-    geojson_rterror("Unable to find 'geometries' in GeoJSON string", 4);
+    geojson_rterror(ctx, "Unable to find 'geometries' in GeoJSON string", 4);
     return NULL;
   }
 
@@ -468,7 +468,7 @@ parse_geojson_geometrycollection(json_ob
     {
       poObjGeom = json_object_array_get_idx( poObjGeoms, i );
       geom = (RTGEOM*)rtcollection_add_rtgeom(ctx, (RTCOLLECTION *)geom,
-                                              parse_geojson(poObjGeom, hasz, root_srid));
+                                              parse_geojson(ctx, poObjGeom, hasz, root_srid));
     }
   }
 
@@ -476,46 +476,46 @@ parse_geojson_geometrycollection(json_ob
 }
 
 static RTGEOM*
-parse_geojson(json_object *geojson, int *hasz, int root_srid)
+parse_geojson(const RTCTX *ctx, json_object *geojson, int *hasz, int root_srid)
 {
   json_object* type = NULL;
   const char* name;
 
   if( NULL == geojson )
   {
-    geojson_rterror("invalid GeoJSON representation", 2);
+    geojson_rterror(ctx, "invalid GeoJSON representation", 2);
     return NULL;
   }
 
-  type = findMemberByName( geojson, "type" );
+  type = findMemberByName( ctx, geojson, "type" );
   if( NULL == type )
   {
-    geojson_rterror("unknown GeoJSON type", 3);
+    geojson_rterror(ctx, "unknown GeoJSON type", 3);
     return NULL;
   }
 
   name = json_object_get_string( type );
 
   if( strcasecmp( name, "Point" )==0 )
-    return parse_geojson_point(geojson, hasz, root_srid);
+    return parse_geojson_point(ctx, geojson, hasz, root_srid);
 
   if( strcasecmp( name, "LineString" )==0 )
-    return parse_geojson_linestring(geojson, hasz, root_srid);
+    return parse_geojson_linestring(ctx, geojson, hasz, root_srid);
 
   if( strcasecmp( name, "Polygon" )==0 )
-    return parse_geojson_polygon(geojson, hasz, root_srid);
+    return parse_geojson_polygon(ctx, geojson, hasz, root_srid);
 
   if( strcasecmp( name, "MultiPoint" )==0 )
-    return parse_geojson_multipoint(geojson, hasz, root_srid);
+    return parse_geojson_multipoint(ctx, geojson, hasz, root_srid);
 
   if( strcasecmp( name, "MultiLineString" )==0 )
-    return parse_geojson_multilinestring(geojson, hasz, root_srid);
+    return parse_geojson_multilinestring(ctx, geojson, hasz, root_srid);
 
   if( strcasecmp( name, "MultiPolygon" )==0 )
-    return parse_geojson_multipolygon(geojson, hasz, root_srid);
+    return parse_geojson_multipolygon(ctx, geojson, hasz, root_srid);
 
   if( strcasecmp( name, "GeometryCollection" )==0 )
-    return parse_geojson_geometrycollection(geojson, hasz, root_srid);
+    return parse_geojson_geometrycollection(ctx, geojson, hasz, root_srid);
 
   rterror(ctx, "invalid GeoJson representation");
   return NULL; /* Never reach */
@@ -550,21 +550,21 @@ rtgeom_from_geojson(const RTCTX *ctx, co
     snprintf(err, 256, "%s (at offset %d)", json_tokener_error_desc(jstok->err), jstok->char_offset);
     json_tokener_free(jstok);
     json_object_put(poObj);
-    geojson_rterror(err, 1);
+    geojson_rterror(ctx, err, 1);
     return NULL;
   }
   json_tokener_free(jstok);
 
-  poObjSrs = findMemberByName( poObj, "crs" );
+  poObjSrs = findMemberByName( ctx, poObj, "crs" );
   if (poObjSrs != NULL)
   {
-    json_object* poObjSrsType = findMemberByName( poObjSrs, "type" );
+    json_object* poObjSrsType = findMemberByName( ctx, poObjSrs, "type" );
     if (poObjSrsType != NULL)
     {
-      json_object* poObjSrsProps = findMemberByName( poObjSrs, "properties" );
+      json_object* poObjSrsProps = findMemberByName( ctx, poObjSrs, "properties" );
       if ( poObjSrsProps )
       {
-        json_object* poNameURL = findMemberByName( poObjSrsProps, "name" );
+        json_object* poNameURL = findMemberByName( ctx, poObjSrsProps, "name" );
         if ( poNameURL )
         {
           const char* pszName = json_object_get_string( poNameURL );
@@ -578,7 +578,7 @@ rtgeom_from_geojson(const RTCTX *ctx, co
     }
   }
 
-  rtgeom = parse_geojson(poObj, &hasz, 0);
+  rtgeom = parse_geojson(ctx, poObj, &hasz, 0);
   json_object_put(poObj);
 
   rtgeom_add_bbox(ctx, rtgeom);


More information about the Pkg-grass-devel mailing list