[postgis-tickets] r17018 - Allocate enough memory in gidx_to_string

Raul raul at rmr.ninja
Thu Nov 15 01:06:55 PST 2018


Author: algunenano
Date: 2018-11-15 01:06:54 -0800 (Thu, 15 Nov 2018)
New Revision: 17018

Modified:
   branches/2.5/NEWS
   branches/2.5/libpgcommon/gserialized_gist.c
Log:
Allocate enough memory in gidx_to_string

References #4236



Modified: branches/2.5/NEWS
===================================================================
--- branches/2.5/NEWS	2018-11-15 09:06:12 UTC (rev 17017)
+++ branches/2.5/NEWS	2018-11-15 09:06:54 UTC (rev 17018)
@@ -18,6 +18,7 @@
   - Schema qualify more functions for raster (Regina Obe)
   - #4216, Revert non-sliced box access (Paul Ramsey)
   - #2767, Documentation for AddRasterConstraint optional parameters (Sunveer Singh)
+  - #4326, Allocate enough memory in gidx_to_string (Raúl Marín)
 
 
 PostGIS 2.5.0

Modified: branches/2.5/libpgcommon/gserialized_gist.c
===================================================================
--- branches/2.5/libpgcommon/gserialized_gist.c	2018-11-15 09:06:12 UTC (rev 17017)
+++ branches/2.5/libpgcommon/gserialized_gist.c	2018-11-15 09:06:54 UTC (rev 17018)
@@ -35,8 +35,13 @@
 
 	if ( a == NULL )
 		return pstrdup("<NULLPTR>");
-
-	str = (char*)palloc(128); /* 15*2*4+8==128 */
+	/* 4 (GIDX_MAX_DIM) *
+	 * 2 (MAX & MIN) *
+	 * 20 (Max representation (e.g. -3.40282346639e+38) [19] + space)
+	 * = 4*2*20 = 160
+	 * + 9 [ 'GIDX(' = 5, ','  = 1, ' )' = 2 + '\0' = 1]
+	 */
+	str = (char *)palloc(169);
 	rv = str;
 	ndims = GIDX_NDIMS(a);
 



More information about the postgis-tickets mailing list