From 993f5a486527b63702a17513b8c6b35e09da9c08 Mon Sep 17 00:00:00 2001 From: Steven Wittens Date: Thu, 9 Feb 2006 08:56:11 +0000 Subject: - #41555: truncate_utf8 infinite loop on invalid utf-8 --- includes/unicode.inc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'includes/unicode.inc') diff --git a/includes/unicode.inc b/includes/unicode.inc index 54fe7bb8b..cd8285514 100644 --- a/includes/unicode.inc +++ b/includes/unicode.inc @@ -193,12 +193,16 @@ function truncate_utf8($string, $len, $wordsafe = FALSE, $dots = FALSE) { return $string; } if ($wordsafe) { + $end = $len; while (($string[--$len] != ' ') && ($len > 0)) {}; + if ($len == 0) { + $len = $end; + } } if ((ord($string[$len]) < 0x80) || (ord($string[$len]) >= 0xC0)) { return substr($string, 0, $len) . ($dots ? ' ...' : ''); } - while (ord($string[--$len]) < 0xC0) {}; + while (--$len >= 0 && ord($string[$len]) >= 0x80 && ord($string[$len]) < 0xC0) {}; return substr($string, 0, $len) . ($dots ? ' ...' : ''); } -- cgit v1.2.3