Opened 17 years ago

Last modified 15 years ago

#970 closed defect

OGRMakeWktCoordinate overflow — at Version 2

Reported by: warmerdam Owned by: Mateusz Łoskot
Priority: normal Milestone: 1.4.2
Component: OGR_SF Version: unspecified
Severity: normal Keywords:
Cc: warmerdam

Description (last modified by Mateusz Łoskot)

From Carlos A. Rueda <carueda@…>

I have just found that some "normal" double values make OGRMakeWktCoordinate to generate a segmentation fault because the internal char arrays are too small for the sprintf formatting. Below is a small program that demonstrates the problem:

$ g++ -Wall -lgdal
$ ./a.out
A extreme but normal double value = 0xffffffffffefffff
   printed with %g = -1.79769e+308
   isnormal(value) returns 1
   printed with %.15f, the format used by OGRMakeWktCoordinate, =
Segmentation fault

Note: I made the test on a liitle-endian machine.

///////////////// ///////////////////////
// OGRMakeWktCoordinate bug
#include "ogr_geometry.h"
#include "ogr_p.h"
#include <cstdio>
#include <cmath>
using namespace std;

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

    printf("A extreme but normal double value = 0xffffffffffefffff\n");
    long dd[2] = { 0xffffffff, 0xffefffff };
    double value = *((double*) dd);

    printf("  printed with %%g = %g\n", value);
    printf("  isnormal(value) returns %d\n", isnormal(value));
    printf("  printed with %%.15f, the format used by
OGRMakeWktCoordinate, = %.15f\n", value);

    // now, the bug:
    char szCoordinate[80];   // as in OGRPoint::exportToWkt

    OGRMakeWktCoordinate(szCoordinate, value, 0.0, 0.0, 2);

    // we dont get this far -> segfault!

    return 0;


Change History (2)

comment:1 by warmerdam, 15 years ago

Cc: warmerdam added
Description: modified (diff)
Milestone: 1.4.2
Owner: changed from warmerdam to Mateusz Łoskot
Priority: highnormal


I think this might already have been dealt with. Could you try and reproduce with 1.4.1?

comment:2 by Mateusz Łoskot, 15 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.