Ticket #1902 (closed defect: fixed)

Opened 6 years ago

Last modified 6 years ago

Data truncation sometimes occurs when fetching data using ogr odbc driver

Reported by: pgerritson Owned by: 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 Download (0.8 KB) - added by mloskot 6 years ago.
Single-record dataset that was used to reproduce and confirm the truncation problem
test-data-truncated-shot.png Download (23.1 KB) - added by mloskot 6 years ago.
A proof-of-problem screenshot

Change History

Changed 6 years ago by warmerdam

  • cc warmerdam added
  • keywords odbc added
  • component changed from default to OGR_SF
  • owner changed from warmerdam to mloskot
  • 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.

Changed 6 years ago 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?

Changed 6 years ago by pgerritson

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

Changed 6 years ago by mloskot

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

Changed 6 years ago by mloskot

A proof-of-problem screenshot

Changed 6 years ago 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)

Note: See TracTickets for help on using tickets.