From 3ca86a3929e201898e692ab3608d0dcf1a8a4bf2 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Mon, 11 Jul 2011 21:29:48 +0530 Subject: [PATCH] Protection against malformed WKT and null --- libraries/gis/pma_gis_factory.php | 7 +++++-- libraries/gis/pma_gis_geometrycollection.php | 21 ++++++++++++++++++++ libraries/gis/pma_gis_visualization.php | 6 ++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/libraries/gis/pma_gis_factory.php b/libraries/gis/pma_gis_factory.php index 7dd1daee95..1ba966910c 100644 --- a/libraries/gis/pma_gis_factory.php +++ b/libraries/gis/pma_gis_factory.php @@ -20,6 +20,9 @@ class PMA_GIS_Factory include_once './libraries/gis/pma_gis_geometry.php'; $type_lower = strtolower($type); + if (! file_exists('./libraries/gis/pma_gis_' . $type_lower . '.php')) { + return false; + } if (include_once './libraries/gis/pma_gis_' . $type_lower . '.php') { switch($type) { case 'MULTIPOLYGON' : @@ -37,10 +40,10 @@ class PMA_GIS_Factory case 'GEOMETRYCOLLECTION' : return PMA_GIS_Geometrycollection::singleton(); default : - throw new Exception('Unknown GIS data type'); + return false; } } else { - throw new Exception('File not found'); + return false; } } } diff --git a/libraries/gis/pma_gis_geometrycollection.php b/libraries/gis/pma_gis_geometrycollection.php index d8c17b3aaa..dd4621dad0 100644 --- a/libraries/gis/pma_gis_geometrycollection.php +++ b/libraries/gis/pma_gis_geometrycollection.php @@ -53,6 +53,9 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry $type = substr($sub_part, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); + if (! $gis_obj) { + continue; + } $scale_data = $gis_obj->scaleRow($sub_part); // Upadate minimum/maximum values for x and y cordinates. @@ -102,6 +105,9 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry $type = substr($sub_part, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); + if (! $gis_obj) { + continue; + } $image = $gis_obj->prepareRowAsPng($sub_part, $label, $color, $scale_data, $image); } return $image; @@ -130,6 +136,9 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry $type = substr($sub_part, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); + if (! $gis_obj) { + continue; + } $image = $gis_obj->prepareRowAsPdf($sub_part, $label, $color, $scale_data, $pdf); } return $pdf; @@ -159,6 +168,9 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry $type = substr($sub_part, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); + if (! $gis_obj) { + continue; + } $row .= $gis_obj->prepareRowAsSvg($sub_part, $label, $color, $scale_data); } return $row; @@ -189,6 +201,9 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry $type = substr($sub_part, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); + if (! $gis_obj) { + continue; + } $row .= $gis_obj->prepareRowAsOl($sub_part, $srid, $label, $color, $scale_data); } return $row; @@ -239,6 +254,9 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry if (isset($gis_data[$i]['gis_type'])) { $type = $gis_data[$i]['gis_type']; $gis_obj = PMA_GIS_Factory::factory($type); + if (! $gis_obj) { + continue; + } $wkt .= $gis_obj->generateWkt($gis_data, $i) . ','; } } @@ -275,6 +293,9 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry $type = substr($sub_part, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); + if (! $gis_obj) { + continue; + } $params = array_merge($params, $gis_obj->generateParams($sub_part, $i)); $i++; } diff --git a/libraries/gis/pma_gis_visualization.php b/libraries/gis/pma_gis_visualization.php index 7c368570b2..31a20bbed7 100644 --- a/libraries/gis/pma_gis_visualization.php +++ b/libraries/gis/pma_gis_visualization.php @@ -313,6 +313,9 @@ class PMA_GIS_Visualization $type = substr($ref_data, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); + if (! $gis_obj) { + continue; + } $scale_data = $gis_obj->scaleRow($row[$this->_settings['spatialColumn']]); // Upadate minimum/maximum values for x and y cordinates. @@ -392,6 +395,9 @@ class PMA_GIS_Visualization $type = substr($ref_data, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); + if (! $gis_obj) { + continue; + } $label = ''; if (isset($this->_settings['labelColumn']) && isset($row[$this->_settings['labelColumn']])