Skip to content

Commit bfccdbd

Browse files
committedAug 16, 2022
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.
1 parent 983a29d commit bfccdbd

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
 

‎ext/mbstring/libmbfl/filters/mbfilter_sjis_mobile.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ static size_t mb_sjis_sb_to_wchar(unsigned char **in, size_t *in_len, uint32_t *
13431343
continue;
13441344
}
13451345
unsigned char c2 = *p++;
1346-
if (((c2 < 'E' || c2 > 'G') && (c2 < 'O' || c2 > 'Q')) || p == e) {
1346+
if ((c2 < 'E' || c2 > 'G') && (c2 < 'O' || c2 > 'Q')) {
13471347
*out++ = MBFL_BAD_INPUT;
13481348
continue;
13491349
}

‎ext/mbstring/tests/sjis_mobile_encodings.phpt

+9
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,15 @@ testSJISVariant($docomo, $nonInvertibleDocomo, 'SJIS-Mobile#DOCOMO');
300300
testSJISVariant($kddi, $nonInvertible, 'SJIS-Mobile#KDDI');
301301
testSJISVariant($softbank, $nonInvertibleSoftbank, 'SJIS-Mobile#SOFTBANK');
302302

303+
// Special Softbank escape sequences can appear at end of string
304+
convertValidString("\x1B\$O", "", "SJIS-Mobile#SOFTBANK", "UTF-8", false);
305+
convertValidString("\x1B\$P", "", "SJIS-Mobile#SOFTBANK", "UTF-8", false);
306+
convertValidString("\x1B\$Q", "", "SJIS-Mobile#SOFTBANK", "UTF-8", false);
307+
// Try invalid escape sequence
308+
convertInvalidString("\x1B\$X", "%", "SJIS-Mobile#SOFTBANK", "UTF-8", false);
309+
// Try truncated escape sequence
310+
convertInvalidString("\x1B\$", "%", "SJIS-Mobile#SOFTBANK", "UTF-8", false);
311+
303312
// Regression test for problem with not allocating enough space in output buffer
304313
// This occurred when the input string was shorter than the output
305314
convertValidString("\xA9\xA9\xA9\xA9", "\xF9\xD6\xF9\xD6\xF9\xD6\xF9\xD6", '8bit', 'SJIS-Mobile#DOCOMO');

0 commit comments

Comments
 (0)