1
0
mirror of https://github.com/php/php-src.git synced 2026-04-26 17:38:14 +02:00

SJIS-Mobile#SOFTBANK string can end immediately after special escape sequence

SJIS-Mobile#SOFTBANK text encoding supports special escape sequences,
which shift the decoder into a mode where each single byte represents
an emoji. To get out of this mode, a 0xF (SHIFT OUT) byte can be
used.

After one of these special escape sequences, the new conversion
code expected to see at least one more byte. However, there doesn't
seem to be any particular reason why it should be treated as an
error condition if a string ends abruptly after one of these
escapes. Well, the escape sequence is useless in that case, but
it is a complete and valid escape sequence.

The legacy conversion code did allow a string to end immediately
after one of these escape sequences. Amend the new code to allow
the same.
This commit is contained in:
Alex Dowad
2022-08-08 08:15:52 +02:00
parent 983a29d3c0
commit bfccdbd858
2 changed files with 10 additions and 1 deletions
@@ -1343,7 +1343,7 @@ static size_t mb_sjis_sb_to_wchar(unsigned char **in, size_t *in_len, uint32_t *
continue;
}
unsigned char c2 = *p++;
if (((c2 < 'E' || c2 > 'G') && (c2 < 'O' || c2 > 'Q')) || p == e) {
if ((c2 < 'E' || c2 > 'G') && (c2 < 'O' || c2 > 'Q')) {
*out++ = MBFL_BAD_INPUT;
continue;
}
@@ -300,6 +300,15 @@ testSJISVariant($docomo, $nonInvertibleDocomo, 'SJIS-Mobile#DOCOMO');
testSJISVariant($kddi, $nonInvertible, 'SJIS-Mobile#KDDI');
testSJISVariant($softbank, $nonInvertibleSoftbank, 'SJIS-Mobile#SOFTBANK');
// Special Softbank escape sequences can appear at end of string
convertValidString("\x1B\$O", "", "SJIS-Mobile#SOFTBANK", "UTF-8", false);
convertValidString("\x1B\$P", "", "SJIS-Mobile#SOFTBANK", "UTF-8", false);
convertValidString("\x1B\$Q", "", "SJIS-Mobile#SOFTBANK", "UTF-8", false);
// Try invalid escape sequence
convertInvalidString("\x1B\$X", "%", "SJIS-Mobile#SOFTBANK", "UTF-8", false);
// Try truncated escape sequence
convertInvalidString("\x1B\$", "%", "SJIS-Mobile#SOFTBANK", "UTF-8", false);
// Regression test for problem with not allocating enough space in output buffer
// This occurred when the input string was shorter than the output
convertValidString("\xA9\xA9\xA9\xA9", "\xF9\xD6\xF9\xD6\xF9\xD6\xF9\xD6", '8bit', 'SJIS-Mobile#DOCOMO');