Uploaded image for project: 'MariaDB Connector/ODBC'
  1. MariaDB Connector/ODBC
  2. ODBC-72

SQLGetData incorrectly handles UTF-16 surrogate pairs

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.0.6, 2.0.13
    • Fix Version/s: 2.0.14, 3.0.1
    • Component/s: None
    • 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.

        Attachments

          Activity

            People

            Assignee:
            Lawrin Lawrin Novitsky
            Reporter:
            dr.obradovic Dragoljub Obradovic
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Git Integration