From 13ee9ef6167061bf21c67b14cddc5d0c3aa0f087 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ra=C3=BAl=20Mar=C3=ADn=20Rodr=C3=ADguez?= Date: Thu, 10 Oct 2019 11:43:01 +0000 Subject: [PATCH] Fix leak in lwcollection_from_wkb_state References #4536 git-svn-id: http://svn.osgeo.org/postgis/branches/2.5@17897 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 1 + liblwgeom/cunit/cu_in_wkb.c | 21 +++++++++++++++++++++ liblwgeom/lwin_wkb.c | 2 ++ 3 files changed, 24 insertions(+) diff --git a/NEWS b/NEWS index 2c681f929..330f2db5d 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,7 @@ PostGIS 2.5.4 - #4519, Fix getSRIDbySRS crash (Raúl Marín) - #4517, Documentation error ST_EndPoint (Samuel Spurling) - #4534, Fix leak in lwcurvepoly_from_wkb_state (Raúl Marín) + - #4536, Fix leak in lwcollection_from_wkb_state (Raúl Marín) PostGIS 2.5.3 diff --git a/liblwgeom/cunit/cu_in_wkb.c b/liblwgeom/cunit/cu_in_wkb.c index cb5c3421a..5a47057f1 100644 --- a/liblwgeom/cunit/cu_in_wkb.c +++ b/liblwgeom/cunit/cu_in_wkb.c @@ -235,6 +235,27 @@ test_wkb_leak(void) 000, 000, 000, 000, 010, 000, 000, 000, 000, 000, 000, 000, 000, 010, 000, 000, 000, 000}; LWGEOM *g = lwgeom_from_wkb(wkb, 36, LW_PARSER_CHECK_NONE); lwgeom_free(g); + + /* OSS-FUZZ https://trac.osgeo.org/postgis/ticket/4536 */ + uint8_t wkb2[319] = { + 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, + 001, 001, 001, 001, 001, 012, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, + 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 051, 001, 001, + 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, + 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 000, 115, 001, 001, 001, 001, + 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 000, 001, 001, 001, 001, 001, 001, 001, + 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, + 001, 001, 001, 001, 001, 001, 000, 000, 000, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, + 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 002, + 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, + 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 207, 001, + 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, + 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 000, 000, 000, 000, 000, + 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001, 001, + 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, + 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001, 001}; + g = lwgeom_from_wkb(wkb2, 319, LW_PARSER_CHECK_NONE); + lwgeom_free(g); } /* diff --git a/liblwgeom/lwin_wkb.c b/liblwgeom/lwin_wkb.c index b1076288c..6488c9eef 100644 --- a/liblwgeom/lwin_wkb.c +++ b/liblwgeom/lwin_wkb.c @@ -660,6 +660,8 @@ static LWCOLLECTION* lwcollection_from_wkb_state(wkb_parse_state *s) geom = lwgeom_from_wkb_state(s); if ( lwcollection_add_lwgeom(col, geom) == NULL ) { + lwgeom_free(geom); + lwgeom_free((LWGEOM *)col); lwerror("Unable to add geometry (%p) to collection (%p)", geom, col); return NULL; } -- 2.40.0