QTextCodec: avoid read-past-buffer in codecForName()


The old code passed a QByteArray to a function taking const char*,
invoking QByteArray::operator const char*() implicitly.

The callee expects the argument to be NUL-terminated, but if the
QByteArray was created fromRawData(), that is not guaranteed.

In newer Qt versions we have nullTerminated(), but this needs to be
picked furthr back, so use a std::string to do the null-termination.

[ChangeLog][QTextCodec] Fixed an out-of-bounds read in codecForName().
which could read past the end of the QByteArray argument if the
argument was created fromRawData() with no NUL-termination.

Amends the start of the public history even in qtbase (where
nameMatch() took QByteArrays, yes, but then proceeded to qstricmp()
them, invoking said operator).

Pick-to: 6.11 6.10 6.8 6.5 5.15
Fixes: QTBUG-145180
Change-Id: If82adb1309993d125d807ffa47afc47229039343
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
commit894079b4932dc878b505056cab9887cca67a011a
parent9a1b7cae846a9bd710d404aebdb79119c9d8d399
authorMarc Mutz <marc.mutz@qt.io>
committerMarc Mutz <marc.mutz@qt.io>
commit timeWed, 25 Mar 2026 11:24:11 +0100