Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-112981

QCollatorSortKey bug in Windows implementation

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.4.0
    • None
    • Windows

    Description

      We experienced a problem where QCollatorSortKey gave the wrong sort order under Windows. So we downloaded the 6.4 source code and found the instantiation of QCollatorSortKey in file corelib/text/qcollator_win.cpp at line 92.

      The code seems to call Windows NLS function LCMapStringW with flag LCMAP_SORTKEY to generate a sort key which it stores in a QString.

      The documentation for LCMapStringW, however, states that:

      • The sort key is stored in the buffer and treated as an opaque array of bytes. The stored values can include embedded 0 bytes at any position.

      (https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-lcmapstringw)

      As a result, QCollatorSortKey::compare() may get the wrong result when it uses QString::compare() to compare the two sort keys. It would be better to store the sort keys in e.g. a QByteArray.

      QTBUG-108756 is probably a symptom of this bug but I made a new one as numeric mode is not the only case where this bug hits.

       

      Kind Regards

      Bjørn Thirud

      I attached a unit test that we used to explore this issue.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            owolff Oliver Wolff
            bjorn.thirud Bjorn Thirud
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes