Skip to content

Commit c6bd085

Browse files
committed
Adjust number of error markers emitted for truncated ISO-2022-JP escape sequence
Fuzzing revealed a small difference between the number of error markers which the legacy ISO-2022-JP and JIS7/8 conversion code emitted for truncated escape sequences and those emitted by the new code. The behavior of the old code seems more reasonable here, so we will imitate it.
1 parent 128768a commit c6bd085

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

ext/mbstring/libmbfl/filters/mbfilter_jis.c

+2
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ static size_t mb_iso2022jp_to_wchar(unsigned char **in, size_t *in_len, uint32_t
480480
/* ESC seen; this is an escape sequence */
481481
if ((e - p) < 2) {
482482
*out++ = MBFL_BAD_INPUT;
483+
if (p != e && (*p == '$' || *p == '('))
484+
p++;
483485
continue;
484486
}
485487

ext/mbstring/tests/iso2022jp_encoding.phpt

+7
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ for ($i = 0; $i <= 0xFF; $i++) {
196196
identifyInvalidString("\x1B", 'JIS');
197197
identifyInvalidString("\x1B", 'ISO-2022-JP');
198198

199+
convertInvalidString("\x1B$", "%", "JIS", "UTF-8");
200+
convertInvalidString("\x1B$", "%", "ISO-2022-JP", "UTF-8");
201+
convertInvalidString("\x1B(", "%", "JIS", "UTF-8");
202+
convertInvalidString("\x1B(", "%", "ISO-2022-JP", "UTF-8");
203+
convertInvalidString("\x1B,", "%,", "JIS", "UTF-8");
204+
convertInvalidString("\x1B,", "%,", "ISO-2022-JP", "UTF-8");
205+
199206
echo "All escape sequences work as expected\n";
200207

201208
foreach (['JIS', 'ISO-2022-JP'] as $encoding) {

0 commit comments

Comments
 (0)