Skip to content

Commit e3fdf31

Browse files
committed
- Fixed bug #52211 (iconv() returns part of string on error)
1 parent 425c528 commit e3fdf31

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585

8686
- Fixed PDO objects binary incompatibility. (Dmitry)
8787

88+
- Fixed bug #52211 (iconv() returns part of string on error). (Felipe)
89+
8890

8991
?? ??? 20??, PHP 5.3.3
9092
- Upgraded bundled PCRE to version 8.01. (Ilia)

ext/iconv/iconv.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -2357,9 +2357,12 @@ PHP_NAMED_FUNCTION(php_if_iconv)
23572357
err = php_iconv_string(in_buffer, (size_t)in_buffer_len,
23582358
&out_buffer, &out_len, out_charset, in_charset);
23592359
_php_iconv_show_error(err, out_charset, in_charset TSRMLS_CC);
2360-
if (out_buffer != NULL) {
2360+
if (err == PHP_ICONV_ERR_SUCCESS && out_buffer != NULL) {
23612361
RETVAL_STRINGL(out_buffer, out_len, 0);
23622362
} else {
2363+
if (out_buffer != NULL) {
2364+
efree(out_buffer);
2365+
}
23632366
RETURN_FALSE;
23642367
}
23652368
}

ext/iconv/tests/bug52211.phpt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug #52211 (iconv() returns part of string on error)
3+
--FILE--
4+
<?php
5+
6+
$str = "PATHOLOGIES MÉDICO-CHIRUR. ADUL. PL";
7+
$str_iconv = iconv('CP850', 'ISO-8859-1', $str );
8+
var_dump($str_iconv);
9+
10+
?>
11+
--EXPECTF--
12+
Notice: iconv(): Detected an illegal character in input string in %s on line %d
13+
bool(false)

0 commit comments

Comments
 (0)