Skip to content

Commit 8e41506

Browse files
committed
[ibmi] Fix error binding Unicode data causing truncation
The PASE binding code converts the Python Unicode object to UTF-8, but passes the size of the PyUnicode object, which is in UCS-2 code units. Thus, if a Python Unicode object has any code points above U+007F, the string lengths will not match and various errors can occur, ranging from data trunctation to UTF-8 not properly formed errors.
1 parent 2c4cfc3 commit 8e41506

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

IBM_DB/ibm_db/ibm_db.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5669,8 +5669,11 @@ static int _python_ibm_db_bind_data( stmt_handle *stmt_res, param_node *curr, Py
56695669
curr->uvalue = NULL;
56705670
}
56715671
curr->uvalue = getUnicodeDataAsSQLTCHAR(bind_data, &isNewBuffer);
5672-
curr->ivalue = PyUnicode_GetSize(bind_data);
5673-
curr->ivalue = curr->ivalue * sizeof(SQLTCHAR);
5672+
#ifdef __PASE__
5673+
curr->ivalue = strlen(curr->uvalue);
5674+
#else
5675+
curr->ivalue = PyUnicode_GetSize(bind_data) * sizeof(SQLTCHAR);
5676+
#endif
56745677
}
56755678
param_length = curr->ivalue;
56765679
if (curr->size != 0) {

0 commit comments

Comments
 (0)