QTextCodec: fix OOB read in TSCII codec


The TSCII codec iterates over the input buffer, and if the currently
processed QChar is not ASCII (has a value larger than 0x80), tries to
analyze the next two QChars.
The problem is that it does so without validating the  i + 1 and i + 2
indices against the input length. As a result, if it can try to read
up to two QChars past the end of the input buffer.

The test is crafted in such way, that a larger buffer is passed as an
input, so it does not trigger ASAN in case of failure, but rather
simply reports an invalid result.

Note that the else branch in the code that now records an error could
instead save the trailing QChar in the converter state, so that the
following chunk could decode it properly.
But this patch does not try to fix the correctness of the encoding, it
simply eliminates the read past the end of the input buffer.

Disclaimer: the tests were developed with the help of AI.

Task-number: QTBUG-149214
Pick-to: 6.12 6.11 6.8 6.5 5.15
Change-Id: Ibbb7cbdae7ddd4cba52bf69002b26dd076d68372
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
commit5841a625142199bf3c58e6ace6fa2c4a8a2c5254
parent8c43de89ec0fe11e715d18150af1f5250b3397ac
authorIvan Solovev <ivan.solovev@qt.io>
committerIvan Solovev <ivan.solovev@qt.io>
commit timeTue, 25 Aug 2026 10:27:46 +0000