tony2001 Tue Oct 11 09:59:19 2005 EDT Modified files: /php-src/ext/iconv iconv.c Log: MF51: fix #34757 (iconv_substr() gives "Unknown error" when offset > string length) http://cvs.php.net/diff.php/php-src/ext/iconv/iconv.c?r1=1.126&r2=1.127&ty=u Index: php-src/ext/iconv/iconv.c diff -u php-src/ext/iconv/iconv.c:1.126 php-src/ext/iconv/iconv.c:1.127 --- php-src/ext/iconv/iconv.c:1.126 Thu Sep 8 07:48:07 2005 +++ php-src/ext/iconv/iconv.c Tue Oct 11 09:59:18 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: iconv.c,v 1.126 2005/09/08 11:48:07 tony2001 Exp $ */ +/* $Id: iconv.c,v 1.127 2005/10/11 13:59:18 tony2001 Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -586,26 +586,38 @@ size_t out_left; unsigned int cnt; - + unsigned int total_len; + + err = _php_iconv_strlen(&total_len, str, nbytes, enc); + if (err != PHP_ICONV_ERR_SUCCESS) { + return err; + } + /* normalize the offset and the length */ - if (offset < 0 || len < 0) { - unsigned int total_len; - err = _php_iconv_strlen(&total_len, str, nbytes, enc); - if (err != PHP_ICONV_ERR_SUCCESS) { - return err; - } - if (offset < 0) { - if ((offset += total_len) < 0) { - offset = 0; - } + if (offset < 0) { + if ((offset += total_len) < 0) { + offset = 0; } - if (len < 0) { - if ((len += (total_len - offset)) < 0) { - len = 0; - } + } + if (len < 0) { + if ((len += (total_len - offset)) < 0) { + len = 0; } } + if (offset >= total_len) { + return PHP_ICONV_ERR_SUCCESS; + } + + if ((offset + len) > total_len) { + /* trying to compute the length */ + len = total_len - offset; + } + + if (len == 0) { + return PHP_ICONV_ERR_SUCCESS; + } + cd1 = iconv_open(GENERIC_SUPERSET_NAME, enc); if (cd1 == (iconv_t)(-1)) {
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php