summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Wittens2006-02-09 08:57:47 (GMT)
committer Steven Wittens2006-02-09 08:57:47 (GMT)
commit8acb44c5440e3e68431962d45b11e2ab4a7b1b12 (patch)
tree6c5b142d6cb748488b55b5fb82b9aadb02663ea0
parenta48a57cac465729a64ec90163fc68402739a5a45 (diff)
- #41555: truncate_utf8 infinite loop on invalid utf-8
-rw-r--r--includes/common.inc7
1 files changed, 5 insertions, 2 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 56c4358..f2c1a15 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -1666,15 +1666,18 @@ function truncate_utf8($string, $len, $wordsafe = 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);
}
- while (ord($string[--$len]) < 0xC0) {};
+ while (--$len >= 0 && ord($string[$len]) >= 0x80 && ord($string[$len]) < 0xC0) {};
return substr($string, 0, $len);
}
-
/**
* Encodes MIME/HTTP header values that contain non-ASCII, UTF-8 encoded
* characters.