diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2019-09-18 08:56:57 +0200 |
---|---|---|
committer | Johan Helsing <johan.helsing@qt.io> | 2019-09-25 13:52:27 +0000 |
commit | 45859d7521074a4921b8459eb0a6e2cc71b9dd5a (patch) | |
tree | afd555c4235f85b1db8fde0b2c365b15606f4bb0 /src | |
parent | 90f9c3c6fdb323a7fd509cb7fc018472cc5d1c13 (diff) |
Client: Don't crash with long window titles using UTF-16 characters
Previously, we set the max length in QString character length, which means
UTF-16 characters (of potentially three bytes) counts as one character. The max
limit of libwayland, however, is in bytes (and the string itself is converted
to UTF-8).
Fix it by dividing the character limit by three because in the worst case each
UTF-16 character will use three bytes when UTF-8 encoded.
Fixes: QTBUG-78478
Change-Id: Idf4721894e0fe6f3cd92bdc6ada7b0ea4199ea63
(cherry picked from commit 1ed0782e93dafb0a3d5ef3a02c9c3999825817ee)
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/client/qwaylandwindow.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp index fba6cc96c..3cd7892a7 100644 --- a/src/client/qwaylandwindow.cpp +++ b/src/client/qwaylandwindow.cpp @@ -309,8 +309,10 @@ void QWaylandWindow::setWindowTitle(const QString &title) const QString formatted = formatWindowTitle(title, separator); const int libwaylandMaxBufferSize = 4096; - // Some parts of the buffer is used for metadata, so subtract 100 to be on the safe side - const int maxLength = libwaylandMaxBufferSize - 100; + // Some parts of the buffer is used for metadata, so subtract 100 to be on the safe side. + // Also, QString is in utf-16, which means that in the worst case each character will be + // three bytes when converted to utf-8 (which is what libwayland uses), so divide by three. + const int maxLength = libwaylandMaxBufferSize / 3 - 100; auto truncated = QStringRef(&formatted).left(maxLength); if (truncated.length() < formatted.length()) { |