Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bound Input Parameter of type SQL_C_WCHAR containing surrogate pairs may be truncated [ODBC160] #155

Closed
firebird-automations opened this issue Feb 6, 2013 · 15 comments

Comments

@firebird-automations
Copy link

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.

Commits: 9fca7df d94a113

@firebird-automations
Copy link
Author

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.

@firebird-automations
Copy link
Author

Modified by: Jojakim Stahl (jstahl)

Attachment: surrogate.patch [ 12285 ]

@firebird-automations
Copy link
Author

Commented by: Jojakim Stahl (jstahl)

a second patch to apply after the first one.
tests revealed a bug in the first patch.

@firebird-automations
Copy link
Author

Modified by: Jojakim Stahl (jstahl)

Attachment: surrogate2.patch [ 12291 ]

@firebird-automations
Copy link
Author

Commented by: Jojakim Stahl (jstahl)

Summary patch based on current cvs-head
The patch invalidates all previously puplished patches.

@firebird-automations
Copy link
Author

Modified by: Jojakim Stahl (jstahl)

Version: 2.0.2 [ 10465 ]

Attachment: bug-160.patch [ 12604 ]

@firebird-automations
Copy link
Author

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)

@firebird-automations
Copy link
Author

Modified by: Jojakim Stahl (jstahl)

Attachment: bug-160-new.patch [ 12605 ]

@firebird-automations
Copy link
Author

Commented by: @alexpotapchenko

Thanks, this patch will be applied for next release after testing.

@firebird-automations
Copy link
Author

Modified by: @alexpotapchenko

Attachment: bug-160.patch [ 12604 ] =>

@firebird-automations
Copy link
Author

Modified by: @alexpotapchenko

Attachment: surrogate.patch [ 12285 ] =>

@firebird-automations
Copy link
Author

Modified by: @alexpotapchenko

Attachment: surrogate2.patch [ 12291 ] =>

@firebird-automations
Copy link
Author

Commented by: @alexpotapchenko

Fixed in CVS

@firebird-automations
Copy link
Author

Modified by: @alexpotapchenko

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 2.0.5 [ 10771 ]

Fix Version: 2.1 Beta [ 10410 ]

@firebird-automations
Copy link
Author

Modified by: @alexpotapchenko

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants