Opened 10 years ago

Closed 6 years ago

#3982 closed defect (fixed)

[PATCH] In .dbf files, large values in numeric fields with zero precision are corrupted.

Reported by: chaitanya Owned by: chaitanya
Priority: normal Milestone: 1.8.1
Component: OGR_SF Version: unspecified
Severity: normal Keywords: shapefile, dbf
Cc: warmerdam

Description

Bug found by Anita Graser. http://lists.osgeo.org/pipermail/gdal-dev/2011-February/027892.html

dbfopen.c is treating all real values with zero precision as integers. Values longer than ten digits are lost this way.

Attachments (2)

dbfopen_patch_for_3982.patch (2.1 KB) - added by Even Rouault 10 years ago.
test_for_3982.patch (1.6 KB) - added by Even Rouault 10 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 10 years ago by Even Rouault

Cc: warmerdam added

This is a bit surprising. A field with more than 10 characters should be handled as a double according to DBFGetFieldInfo()

    else if( psDBF->pachFieldType[iField] == 'N' 
             || psDBF->pachFieldType[iField] == 'F' )
    {
	if( psDBF->panFieldDecimals[iField] > 0 
            || psDBF->panFieldSize[iField] > 10 )
	    return( FTDouble );
	else
	    return( FTInteger );
    }

The issue is that an "integer" of more than 10 digits cannot be represented into a double with exact precision (thus Int64 support might help a bit), but that doesn't seem to be the issue reported by the user here.

comment:2 Changed 10 years ago by chaitanya

The values are being read alright. Problem is with the writing.

comment:3 Changed 10 years ago by Even Rouault

Summary: In .dbf files, large values in numeric fields with zero precision are corrupted.[PATCH] In .dbf files, large values in numeric fields with zero precision are corrupted.

Frank,

attached a patch to dbfopen.c to fix the issue and the autotest that check it.

In fact, I'm wondering if the "if( psDBF->panFieldDecimals[iField] == 0 && .... )" has any advantage over using the else part in all cases

Changed 10 years ago by Even Rouault

Changed 10 years ago by Even Rouault

Attachment: test_for_3982.patch added

comment:4 Changed 6 years ago by Jukka Rahkonen

Patch has probably not been applied nor denied yet.

comment:5 Changed 6 years ago by chaitanya

Resolution: fixed
Status: newclosed

Fixed in #5625

Note: See TracTickets for help on using tickets.