Fix out-of-bounds table read in wxMBConvUTF7::ToWChar()

In wxMBConvUTF7::ToWChar() the value of the byte after '+' was cast to
"unsigned", which meant that on the platforms with signed bytes values
greater than 0x80 were sign-extended to a ~4GiB index which was (way)
out of bounds for a 256-entry table.

Fix the code by casting to "unsigned char", like the cc lookup just
above already does.

Closes #26517.
This commit is contained in:
dxbjavid
2026-05-27 15:56:54 +02:00
committed by Vadim Zeitlin
parent 975dc5e53d
commit f5c81bc5de
2 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -702,7 +702,7 @@ size_t wxMBConvUTF7::ToWChar(wchar_t *dst, size_t dstLen,
len++;
src++;
}
else if ( utf7unb64[(unsigned)*src] == 0xff )
else if ( utf7unb64[(unsigned char)*src] == 0xff )
{
// empty encoded chunks are not allowed
if ( !len )
+5
View File
@@ -1495,4 +1495,9 @@ TEST_CASE("wxMBConv::cMB2WC", "[mbconv][mb2wc]")
CHECK( wxConvUTF7.cMB2WC("").length() == 0 );
CHECK( wxConvUTF7.cMB2WC(wxCharBuffer()).length() == 0 );
CHECK( wxConvUTF7.cMB2WC("+AKM-").length() == 1 );
// A non-ASCII byte right after the shift character used to be read past
// the end of the base-64 decoding table (signed char index), now it's
// just rejected as an invalid encoded chunk.
CHECK( wxConvUTF7.cMB2WC("+\xc3").length() == 0 );
}