mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-08-17 17:02:51 +08:00
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:
@@ -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 )
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user