Skip to content

Commit 2de0ffd

Browse files
Comment realloc moving the buffer
1 parent 97bad32 commit 2de0ffd

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

‎ext/mbstring/libmbfl/mbfl/mbfl_encoding.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ static inline zend_result mb_convert_buf_ensure(mb_convert_buf *buf, unsigned ch
168168
if ((size_t)(*limit - *out) < needed) {
169169
size_t oldsize = *limit - (unsigned char*)ZSTR_VAL((buf)->str);
170170
size_t newsize = oldsize + MAX(oldsize >> 1, needed);
171+
/* Save offset before realloc, which may move the buffer, subtracting invalidated pointers afterwards is UB */
171172
size_t out_offset = *out - (unsigned char*)ZSTR_VAL((buf)->str);
172173
zend_string *newstr = safe_ferealloc((buf)->str, 1, newsize, _ZSTR_STRUCT_SIZE(0), /* fallible */ true);
173174
if (!newstr) {

0 commit comments

Comments
 (0)