Skip to content

Commit 1f17b54

Browse files
committed
Fix buffer overflow bug in HZ text conversion code
1 parent 0154a5a commit 1f17b54

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

ext/mbstring/libmbfl/filters/mbfilter_hz.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static void mb_wchar_to_hz(uint32_t *in, size_t len, mb_convert_buf *buf, bool e
372372
} else if (s < 0x80) {
373373
/* ASCII */
374374
if (buf->state != ASCII) {
375-
MB_CONVERT_BUF_ENSURE(buf, out, limit, len + 2);
375+
MB_CONVERT_BUF_ENSURE(buf, out, limit, len + 3);
376376
out = mb_convert_buf_add2(out, '~', '}');
377377
buf->state = ASCII;
378378
}
@@ -385,11 +385,12 @@ static void mb_wchar_to_hz(uint32_t *in, size_t len, mb_convert_buf *buf, bool e
385385
} else {
386386
/* GB 2312-80 */
387387
if (buf->state != GB2312) {
388-
MB_CONVERT_BUF_ENSURE(buf, out, limit, len + 2);
388+
MB_CONVERT_BUF_ENSURE(buf, out, limit, len + 4);
389389
out = mb_convert_buf_add2(out, '~', '{');
390390
buf->state = GB2312;
391+
} else {
392+
MB_CONVERT_BUF_ENSURE(buf, out, limit, len + 2);
391393
}
392-
MB_CONVERT_BUF_ENSURE(buf, out, limit, len + 2);
393394
out = mb_convert_buf_add2(out, (s >> 8) & 0x7F, s & 0x7F);
394395
}
395396
}

0 commit comments

Comments
 (0)