Opened 14 years ago

Closed 14 years ago

#346 closed defect (fixed)

WKBWriter writes corrupt output for 2D geometries with outputDimension set to 3

Reported by: warmerdam Owned by: warmerdam
Priority: major Milestone:
Component: Core Version: main
Severity: Unassigned Keywords: WKBWriter
Cc:

Description

The following simple C program using GEOS throws an Unexpected EOF parsing WKBgeom2 exception because the WKB produced by the WKBWriter is corrupt. The WKBWriter class writes the 3D flag in the type field if outputDimension is set to 3 on the writer (per WriteGeometryType() method), but only writes 3D coordinates if the source geometry is 3D (per writeCoordinate() method).

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

#include <geos_c.h> 

void geosMsg( const char *fmt, ... )

{
    va_list ap;

    va_start(ap, fmt);
    vfprintf( stderr, fmt, ap );
    va_end(ap);

    return;
}

/************************************************************************/
/*                                main()                                */
/************************************************************************/
int main( int argc, char ** argv )

{
    const char *src_wkt = "POINT(-117 33)";
    unsigned char *dst_wkb;

    GEOSGeometry *geom, *geom2;
    GEOSContextHandle_t hCtx;
    size_t wkb_size;


    hCtx = initGEOS_r( geosMsg, geosMsg );

    geom = GEOSGeomFromWKT_r( hCtx, src_wkt );

    GEOS_setWKBOutputDims_r( hCtx, 3 );
    dst_wkb = GEOSGeomToWKB_buf_r( hCtx, geom, &wkb_size );

    printf( "wkb_size = %d\n", (int) wkb_size );

    geom2 = GEOSGeomFromWKB_buf_r( hCtx, dst_wkb, wkb_size );
    printf( "geom2 = %p\n", geom2 );
    
    GEOSFree_r( hCtx, dst_wkb );

    exit( 0 );
}

Change History (1)

comment:1 by warmerdam, 14 years ago

Resolution: fixed
Status: newclosed

Corrected in trunk as part of the larger commit (r2995).

Note: See TracTickets for help on using tickets.