Skip to content

Commit d27d54e

Browse files
liskegromandreas
authored andcommitted
fix: Utf8_truncate crashes on empty strings due to off-by-one-error
`WARNING: [pool grommunio-sync-pool] child 111823 said into stderr: "NOTICE: PHP message: PHP Fatal error: Uncaught ValueError: strrpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) in /usr/share/grommunio-sync/lib/utils/utils.php:352"` When $string is empty the value $offset will be set to `-1`, which is not a valid position for strrpos.
1 parent a9cb4a4 commit d27d54e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/utils/utils.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ public static function GetTruncSize($truncation) {
335335
* @return string truncated string
336336
*/
337337
public static function Utf8_truncate($string, $length, $htmlsafe = false) {
338+
// skip empty strings
339+
if (empty($string)) {
340+
return "";
341+
}
342+
338343
// make sure length is always an integer
339344
$length = (int) $length;
340345

0 commit comments

Comments
 (0)