[PHP-CVS] [php-src] master: Stop grapheme_str_split from using UBRK_DONE as a byte index (#23349)

[email protected] (Ilia Alshanetsky via Weilin Du)
Newsgroups php.cvs
Message-ID <[email protected]>
Author: Ilia Alshanetsky (iliaal)
Committer: Weilin Du (LamentXU123)
Date: 2026-08-18T22:55:07+08:00

Commit: https://github.com/php/php-src/commit/9002df8a4133cff51bcf2051e48a1beec9fc2f12
Raw diff: https://github.com/php/php-src/commit/9002df8a4133cff51bcf2051e48a1beec9fc2f12.diff

Stop grapheme_str_split from using UBRK_DONE as a byte index (#23349)

When the last grapheme_str_split() group is short, ubrk_next() returns
UBRK_DONE and the loop still advanced pstr by -1 - current. Skip that
update when the iterator is done, matching the grapheme_strrev() fix.

Other ubrk_next() loops in grapheme_string.c and grapheme_util.c were
audited and already guard UBRK_DONE before using the position as an
offset.

Closes #23349

Changed paths:
  M  NEWS
  M  ext/intl/grapheme/grapheme_string.c


Diff:

diff --git a/NEWS b/NEWS
index 4cafbbd5a900..f65c07cf4a7e 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,7 @@ PHP                                                                        NEWS
     for UTF-8 strings). (ColumbusLabs)
   . Fixed Locale::parseLocale() reading past a trailing '-' or '_'.
     (iliaal, Xuyang Zhang)
+  . Fixed grapheme_str_split() treating UBRK_DONE as a byte index. (iliaal)
 
 - Opcache:
   . Fixed opcache.protect_memory race under ZTS. (realFlowControl)
diff --git a/ext/intl/grapheme/grapheme_string.c b/ext/intl/grapheme/grapheme_string.c
index fe80e06adce4..6b418e65cff4 100644
--- a/ext/intl/grapheme/grapheme_string.c
+++ b/ext/intl/grapheme/grapheme_string.c
@@ -896,9 +896,9 @@ PHP_FUNCTION(grapheme_str_split)
 				add_next_index_stringl(return_value, pstr, pos - current);
 				end = pstr + pos - current;
 				i = 0;
+				pstr += pos - current;
+				current = pos;
 			}
-			pstr += pos - current;
-			current = pos;
 		} else {
 			i += 1;
 		}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.