Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/iconv/iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,8 @@ static php_iconv_err_t _php_iconv_mime_encode(smart_str *pretval, const char *fn
goto out;
}

buf = safe_emalloc(1, max_line_len, 5);

cd_pl = iconv_open(ICONV_ASCII_ENCODING, enc);
if (cd_pl == (iconv_t)(-1)) {
if (errno == EINVAL) {
Expand All @@ -962,8 +964,6 @@ static php_iconv_err_t _php_iconv_mime_encode(smart_str *pretval, const char *fn
goto out;
}

buf = safe_emalloc(1, max_line_len, 5);

char_cnt = max_line_len;

_php_iconv_appendl(pretval, fname, fname_nbytes, cd_pl);
Expand Down
13 changes: 13 additions & 0 deletions ext/iconv/tests/gh17399.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
GH-17399 (iconv memory leak with large line-length in iconv_mime_encode)
--EXTENSIONS--
iconv
--FILE--
<?php
$options = array(
'line-length' => PHP_INT_MAX,
);
iconv_mime_encode('Subject', 'test', $options);
?>
--EXPECTF--
Fatal error: Allowed memory size of %d bytes exhausted %s in %s on line %d
Loading