Changeset 19592


Ignore:
Timestamp:
May 1, 2010 2:44:22 PM (6 years ago)
Author:
rouault
Message:

LIBKML: avoid crash when reading POLYGON EMPTY and POINT EMPTY; better handling of other empty geometries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gdal/ogr/ogrsf_frmts/libkml/ogrlibkmlgeometry.cpp

    r19535 r19592  
    112112
    113113        poOgrPoint = ( OGRPoint * ) poOgrGeom;
    114 
    115         x = poOgrPoint->getX (  );
    116         y = poOgrPoint->getY (  );
    117 
    118         if ( x > 180 )
    119             x -= 360;
    120 
    121         coordinates = poKmlFactory->CreateCoordinates (  );
    122         coordinates->add_latlng ( y, x );
    123         poKmlGeometry = poKmlPoint = poKmlFactory->CreatePoint (  );
    124         poKmlPoint->set_coordinates ( coordinates );
     114        if (poOgrPoint->getCoordinateDimension() == 0)
     115        {
     116            poKmlGeometry = poKmlPoint = poKmlFactory->CreatePoint (  );
     117        }
     118        else
     119        {
     120            x = poOgrPoint->getX (  );
     121            y = poOgrPoint->getY (  );
     122
     123            if ( x > 180 )
     124                x -= 360;
     125
     126            coordinates = poKmlFactory->CreateCoordinates (  );
     127            coordinates->add_latlng ( y, x );
     128            poKmlGeometry = poKmlPoint = poKmlFactory->CreatePoint (  );
     129            poKmlPoint->set_coordinates ( coordinates );
     130        }
    125131
    126132        break;
     
    367373        if ( poKmlPoint->has_coordinates (  ) ) {
    368374            poKmlCoordinates = poKmlPoint->get_coordinates (  );
    369             oKmlVec = poKmlCoordinates->get_coordinates_array_at ( 0 );
    370 
    371             if ( oKmlVec.has_altitude (  ) )
    372                 poOgrPoint = new OGRPoint ( oKmlVec.get_longitude (  ),
    373                                             oKmlVec.get_latitude (  ),
    374                                             oKmlVec.get_altitude (  ) );
     375            nCoords = poKmlCoordinates->get_coordinates_array_size (  );
     376            if (nCoords > 0)
     377            {
     378                oKmlVec = poKmlCoordinates->get_coordinates_array_at ( 0 );
     379
     380                if ( oKmlVec.has_altitude (  ) )
     381                    poOgrPoint = new OGRPoint ( oKmlVec.get_longitude (  ),
     382                                                oKmlVec.get_latitude (  ),
     383                                                oKmlVec.get_altitude (  ) );
     384                else
     385                    poOgrPoint = new OGRPoint ( oKmlVec.get_longitude (  ),
     386                                                oKmlVec.get_latitude (  ) );
     387
     388                poOgrGeometry = poOgrPoint;
     389            }
    375390            else
    376                 poOgrPoint = new OGRPoint ( oKmlVec.get_longitude (  ),
    377                                             oKmlVec.get_latitude (  ) );
    378 
    379             poOgrGeometry = poOgrPoint;
     391            {
     392                poOgrGeometry = new OGRPoint();
     393            }
     394        }
     395        else
     396        {
     397            poOgrGeometry = new OGRPoint();
    380398        }
    381399
     
    384402    case kmldom::Type_LineString:
    385403        poKmlLineString = AsLineString ( poKmlGeometry );
     404        poOgrLineString = new OGRLineString (  );
    386405        if ( poKmlLineString->has_coordinates (  ) ) {
    387406            poKmlCoordinates = poKmlLineString->get_coordinates (  );
    388 
    389             poOgrLineString = new OGRLineString (  );
    390407
    391408            nCoords = poKmlCoordinates->get_coordinates_array_size (  );
     
    401418                        addPoint ( oKmlVec.get_longitude (  ),
    402419                                   oKmlVec.get_latitude (  ) );
    403 
    404                 poOgrGeometry = poOgrLineString;
    405420            }
    406421        }
     422        poOgrGeometry = poOgrLineString;
    407423
    408424        break;
    409425    case kmldom::Type_LinearRing:
    410426        poKmlLinearRing = AsLinearRing ( poKmlGeometry );
     427        poOgrLinearRing = new OGRLinearRing (  );
    411428        if ( poKmlLinearRing->has_coordinates (  ) ) {
    412429            poKmlCoordinates = poKmlLinearRing->get_coordinates (  );
    413 
    414             poOgrLinearRing = new OGRLinearRing (  );
    415430
    416431            nCoords = poKmlCoordinates->get_coordinates_array_size (  );
     
    426441                        addPoint ( oKmlVec.get_longitude (  ),
    427442                                   oKmlVec.get_latitude (  ) );
    428 
    429                 poOgrGeometry = poOgrLinearRing;
    430443            }
    431444        }
     445        poOgrGeometry = poOgrLinearRing;
    432446
    433447        break;
     
    440454            poKmlOuterRing = poKmlPolygon->get_outerboundaryis (  );
    441455            poKmlLinearRing = poKmlOuterRing->get_linearring (  );
    442             poOgrTmpGeometry = kml2geom ( poKmlLinearRing, poOgrSRS );
    443 
    444             poOgrPolygon->
    445                 addRingDirectly ( ( OGRLinearRing * ) poOgrTmpGeometry );
     456            if (poKmlLinearRing)
     457            {
     458                poOgrTmpGeometry = kml2geom ( poKmlLinearRing, poOgrSRS );
     459
     460                poOgrPolygon->
     461                    addRingDirectly ( ( OGRLinearRing * ) poOgrTmpGeometry );
     462            }
    446463
    447464        }
     
    450467            poKmlInnerRing = poKmlPolygon->get_innerboundaryis_array_at ( i );
    451468            poKmlLinearRing = poKmlInnerRing->get_linearring (  );
    452             poOgrTmpGeometry = kml2geom ( poKmlLinearRing, poOgrSRS );
    453 
    454             poOgrPolygon->
    455                 addRingDirectly ( ( OGRLinearRing * ) poOgrTmpGeometry );
     469            if (poKmlLinearRing)
     470            {
     471                poOgrTmpGeometry = kml2geom ( poKmlLinearRing, poOgrSRS );
     472
     473                poOgrPolygon->
     474                    addRingDirectly ( ( OGRLinearRing * ) poOgrTmpGeometry );
     475            }
    456476        }
    457477        poOgrGeometry = poOgrPolygon;
Note: See TracChangeset for help on using the changeset viewer.