[ODBC-72] SQLGetData incorrectly handles UTF-16 surrogate pairs Created: 2016-12-07  Updated: 2017-03-02  Resolved: 2017-03-02

Status: Closed
Project: MariaDB Connector/ODBC
Component/s: None
Affects Version/s: 1.0.6, 2.0.13
Fix Version/s: 2.0.14, 3.0.1

Type: Bug Priority: Blocker
Reporter: Dragoljub Obradovic Assignee: Lawrin Novitsky
Resolution: Fixed Votes: 0
Labels: None


 Description   

When calling SQLGetData to read a variable length TEXT utf8mb4 field as SQL_C_WCHAR, if the text contains utf-8 4 bytes character (UTF-16 surrogate pair) and it falls at the end of the buffer so only one half can fit, the successive calls to the function return the same content, making an indefinite loop.

For example, if the field contains Unicode codes 'a', 0xD83D, 0xDE18, and 'd', and the buffer is 6 bytes (3 wchar_t's), the function puts 'a' and high surrogate 0xD83D and 0 into the buffer, returns SQL_SUCCESS_WITH_INFO with SQL state [01004], but the successive calls do not advance but keep returning the same results.

The significant lines of code are as follows:

SQLWCHAR temp_stringW[3];
while (!Success)

{ rc=SQLGetData(hstmt,col,SQL_C_WCHAR,temp_stringW,sizeof(temp_stringW),&size); ... }

NOTE: While typing this description, this web site reported an exception when the above sample text contained real character, like 'a<smiley>d'. No need to mention that I had to retype the whole text from scratch. Obviously, all MySQL flavours are simple plagued with bugs when it comes to handling 4-byte utf8 characters! That is the reason why I cannot provide here the exact sample string. Here it is in UTF-8 bytes: 61 F0 9F 98 98 64.



 Comments   
Comment by Lawrin Novitsky [ 2016-12-07 ]

Thank you for your bug report - that is what helps to reduce number of bugs. And looks like jira also has problems with 4-bytes utf8

Comment by Lawrin Novitsky [ 2017-03-02 ]

Fix and testcase have to be pushed into 2.0 tree as rev. 3f3ec84247e7b109277fb01c59f153e3fc47dda3

Generated at Thu Feb 08 03:26:01 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.