Bound Input Parameter of type SQL_C_WCHAR containing surrogate pairs may be truncated [ODBC160]
firebird-automations opened this issue · 15 comments
Submitted by: Jojakim Stahl (jstahl)
Attachments:
bug-160-new.patch
Do the following (pseudo-code)
create table test (
strfield varchar(30) character set UTF8
)
SQLDriverConnect( ... CHARSET=UTF8 ...)
SQLPrepareW(hStmt, "insert into test values (?)", SQL_NTS)
SQLBindParameter(hStmt, 1, SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_VARCHAR, 30, 0, str_field, sizeof(str_field), &str_field_len);
with str_field containing min 30 chars, and min. one of them beeing a surrogate pairs, means a string conating more than 30 wchar_t entities.
The string can be converted to the UTF8 field without any loss, because FB allows up to 30*4 bytes for the field. However, the driver does assume, that one wchar_t unit results in one char (covering up to 4 bytes in UTF8). The input value will be truncated to 30 wchar_t entities instead of 30 charachters.
Commented by: Jojakim Stahl (jstahl)
This patch solves the issue.
I tried to solve it with as minimal as possible code changes (at least I hope so).
The downside is one additional scan of the input string.
Otherwise I had to rework all the WcsToMbs function signatures in order to in- and output detailed string length and character count information to/from these functions.
Modified by: Jojakim Stahl (jstahl)
Attachment: surrogate.patch [ 12285 ]
Commented by: Jojakim Stahl (jstahl)
a second patch to apply after the first one.
tests revealed a bug in the first patch.
Modified by: Jojakim Stahl (jstahl)
Attachment: surrogate2.patch [ 12291 ]
Commented by: Jojakim Stahl (jstahl)
Summary patch based on current cvs-head
The patch invalidates all previously puplished patches.
Modified by: Jojakim Stahl (jstahl)
Version: 2.0.2 [ 10465 ]
Attachment: bug-160.patch [ 12604 ]
Commented by: Jojakim Stahl (jstahl)
Sorry, the summary patch contained changes for each line due to oel-style problem.
Please use only the "bug-160-new.patch".
The other attachments can be deleted. (I do not have permissions to do so)
Modified by: Jojakim Stahl (jstahl)
Attachment: bug-160-new.patch [ 12605 ]
Commented by: @alexpotapchenko
Thanks, this patch will be applied for next release after testing.
Modified by: @alexpotapchenko
Attachment: bug-160.patch [ 12604 ] =>
Modified by: @alexpotapchenko
Attachment: surrogate.patch [ 12285 ] =>
Modified by: @alexpotapchenko
Attachment: surrogate2.patch [ 12291 ] =>
Commented by: @alexpotapchenko
Fixed in CVS
Modified by: @alexpotapchenko
status: Open [ 1 ] => Resolved [ 5 ]
resolution: Fixed [ 1 ]
Fix Version: 2.0.5 [ 10771 ]
Fix Version: 2.1 Beta [ 10410 ]
Modified by: @alexpotapchenko
status: Resolved [ 5 ] => Closed [ 6 ]