Skip to content

Commit a38c7e5

Browse files
committed
Add assertions to help catch buffer overflows in mbstring text conversion code
1 parent ae05c96 commit a38c7e5

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

ext/mbstring/libmbfl/mbfl/mbfl_convert.c

+1
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ zend_string* mb_fast_convert(zend_string *str, const mbfl_encoding *from, const
360360

361361
while (in_len) {
362362
size_t out_len = from->to_wchar(&in, &in_len, wchar_buf, 128, &state);
363+
ZEND_ASSERT(out_len <= 128);
363364
to->from_wchar(wchar_buf, out_len, &buf, !in_len);
364365
}
365366

ext/mbstring/libmbfl/mbfl/mbfl_encoding.h

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ static inline void mb_convert_buf_init(mb_convert_buf *buf, size_t initsize, uin
154154
}
155155

156156
#define MB_CONVERT_BUF_ENSURE(buf, out, limit, needed) \
157+
ZEND_ASSERT(out <= limit); \
157158
if ((limit - out) < (needed)) { \
158159
size_t oldsize = limit - (unsigned char*)ZSTR_VAL(buf->str); \
159160
size_t newsize = oldsize + MAX(oldsize >> 1, needed); \

0 commit comments

Comments
 (0)