Opened 16 years ago

Closed 16 years ago

#1902 closed defect (fixed)

Data truncation sometimes occurs when fetching data using ogr odbc driver

Reported by: pgerritson Owned by: Mateusz Łoskot
Priority: normal Milestone: 1.4.3
Component: OGR_SF Version: svn-trunk
Severity: normal Keywords: odbc
Cc: warmerdam

Description

In cpl_odbc.cpp, in CPLODBCStatement::Fetch, when the column fetch_type is SQL_C_CHAR and the column data is exactly 511 characters long, the data is returned missing the last character.

In this case, the initial SQLGetData call on line 836 returns SQL_SUCCESS_WITH_INFO, and cbDataLen is 511, and szWrkData has the first 510 characters plus a binary 0 at index 510.

It seems that the bug is due to an improper edge condition on line 859: if( cbDataLen > (_SQLLEN)(sizeof(szWrkData)-1) )

In this case, when cbDataLen is exactly 511, this "if" condition is not satisfied, and the code labelled " trimming the extra terminators: bug 990" does not get executed.

The next call to SQLGetData (on line 864) correctly reads the last character of the field, but the memcpy on line 907 places this last character at index 511, after the binary zero at index 510.

Changing the "if" statement on line 859 to be : if( cbDataLen >= (_SQLLEN)(sizeof(szWrkData)-1) ) seems to fix the problem.

Attachments (2)

test_data.sql (812 bytes ) - added by Mateusz Łoskot 16 years ago.
Single-record dataset that was used to reproduce and confirm the truncation problem
test-data-truncated-shot.png (23.1 KB ) - added by Mateusz Łoskot 16 years ago.
A proof-of-problem screenshot

Download all attachments as: .zip

Change History (6)

comment:1 by warmerdam, 16 years ago

Cc: warmerdam added
Component: defaultOGR_SF
Keywords: odbc added
Milestone: 1.4.3
Owner: changed from warmerdam to Mateusz Łoskot

Mateusz,

The described bug and fix seem reasonable to me, but could you try and reproduce the problem and verify the fix before applying it? The fix should go into 1.4 as well as trunk.

comment:2 by Mateusz Łoskot, 16 years ago

Status: newassigned

pgerritson,

Could you tell me what operating system and ODBC layer do you use? Is it Windows or Unix + unixODBC or yet another combination?

comment:3 by pgerritson, 16 years ago

I was running on Windows, connecting with ODBC to Teradata.

by Mateusz Łoskot, 16 years ago

Attachment: test_data.sql added

Single-record dataset that was used to reproduce and confirm the truncation problem

by Mateusz Łoskot, 16 years ago

A proof-of-problem screenshot

comment:4 by Mateusz Łoskot, 16 years ago

Resolution: fixed
Status: assignedclosed
Version: unspecifiedsvn-trunk

I've reproduced this problem and I confirm Pete's results. I applied suggested fix to trunk (r12531) and branches/1.4 (r12532)

Note: See TracTickets for help on using tickets.