Opened 19 years ago

Last modified 17 years ago

#970 closed defect

OGRMakeWktCoordinate overflow — at Version 1

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 warmerdam)

From Carlos A. Rueda <carueda@ucdavis.edu>

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 wktcoordbug.cc -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, =
-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000000000000
Segmentation fault

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

Best regards,

carlos


/////////////////  wktcoordbug.cc ///////////////////////
// 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 (1)

comment:1 by warmerdam, 17 years ago

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

Mateusz,

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

Note: See TracTickets for help on using tickets.