Ticket #1902 (closed defect: fixed)

Opened 9 months ago

Last modified 8 months ago

Data truncation sometimes occurs when fetching data using ogr odbc driver

Reported by: pgerritson Assigned to: mloskot
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

test_data.sql (0.8 kB) - added by mloskot on 10/24/07 22:31:03.
Single-record dataset that was used to reproduce and confirm the truncation problem
test-data-truncated-shot.png (23.1 kB) - added by mloskot on 10/24/07 22:38:21.
A proof-of-problem screenshot

Change History

10/13/07 12:42:38 changed by warmerdam

  • keywords set to odbc.
  • owner changed from warmerdam to mloskot.
  • component changed from default to OGR_SF.
  • cc set to warmerdam.
  • milestone set to 1.4.3.

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.

10/19/07 10:56:15 changed by mloskot

  • status changed from new to assigned.

pgerritson,

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

10/19/07 11:19:41 changed by pgerritson

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

10/24/07 22:31:03 changed by mloskot

  • attachment test_data.sql added.

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

10/24/07 22:38:21 changed by mloskot

  • attachment test-data-truncated-shot.png added.

A proof-of-problem screenshot

10/24/07 22:52:56 changed by mloskot

  • status changed from assigned to closed.
  • version changed from unspecified to svn-trunk.
  • resolution set to fixed.

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