QUtf32: fix bad assertion in convertFromUnicode

Looks like it was copied from QUtf16::convertFromUnicode(), but for the
UTF-32 case that is not correct. UTF-16 to UTF-32 conversions can change
the length of the string due to surrogates.

There are unit test tests for creating and parsing UTF-32 headers, and
for detecting content as UTF-32, but there aren't any for UTF-32
conversions. I don't have time to add a full test for that.

Fixes: QTBUG-97122
Pick-to: 6.2 6.1
Change-Id: Ic17a33f599b844d8ab5dfffd16ab2c4cb6b0547d
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Thiago Macieira 2021-10-05 08:33:17 -07:00
parent 2b77e779ce
commit 333b40a12e

View File

@ -1027,8 +1027,7 @@ QByteArray QUtf32::convertFromUnicode(QStringView in, QStringConverter::State *s
length += 4;
QByteArray ba(length, Qt::Uninitialized);
char *end = convertFromUnicode(ba.data(), in, state, endian);
Q_ASSERT(end - ba.constData() == length);
Q_UNUSED(end);
ba.truncate(end - ba.constData());
return ba;
}