Commit be5442d56fb for php

commit be5442d56fba89e682d639110e1202fec93e7ade
Author: Weilin Du <weilindu@php.net>
Date:   Sat Oct 3 00:10:37 2026 +0800

    ext/intl: Fix overlapping grapheme matches with negative search offsets (#24028)

diff --git a/NEWS b/NEWS
index 99df5910c8b..fb0f05f502b 100644
--- a/NEWS
+++ b/NEWS
@@ -74,6 +74,8 @@ PHP                                                                        NEWS
   . Fixed grapheme_strstr() and grapheme_strpos() missing canonically
     equivalent matches, and grapheme searches reporting ICU errors for empty
     haystacks. (Weilin Du)
+  . Fixed grapheme_strrpos() and grapheme_strripos() skipping overlapping matches
+    when using a negative offset. (Weilin Du)

 - Lexbor:
   . Merge patches lexbor/lexbor@8a14bc0 and lexbor/lexbor@f67ce4b, fixing a
diff --git a/ext/intl/grapheme/grapheme_util.c b/ext/intl/grapheme/grapheme_util.c
index dbe80d96276..cd337055d45 100644
--- a/ext/intl/grapheme/grapheme_util.c
+++ b/ext/intl/grapheme/grapheme_util.c
@@ -184,6 +184,12 @@ int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle,
 					break;
 				}
 				prev_pos = char_pos;
+				int32_t next_pos = ubrk_following(bi, char_pos);
+				if (next_pos == UBRK_DONE) {
+					break;
+				}
+				usearch_setOffset(src, next_pos, &status);
+				STRPOS_CHECK_STATUS(status, "Invalid search offset");
 			} while(1);
 		}
 	} else {
diff --git a/ext/intl/tests/grapheme_strrpos_negative_offset_overlap.phpt b/ext/intl/tests/grapheme_strrpos_negative_offset_overlap.phpt
new file mode 100644
index 00000000000..aa7fb349ba4
--- /dev/null
+++ b/ext/intl/tests/grapheme_strrpos_negative_offset_overlap.phpt
@@ -0,0 +1,32 @@
+--TEST--
+grapheme_strrpos() and grapheme_strripos() find overlapping matches with negative offsets
+--EXTENSIONS--
+intl
+--FILE--
+<?php
+foreach (['a', "\u{00E9}", "e\u{0301}", "\u{1F600}"] as $grapheme) {
+    foreach (['grapheme_strrpos', 'grapheme_strripos'] as $function) {
+        $positions = [];
+        foreach ([0, 1, -1, -2, -3] as $offset) {
+            $positions[] = $function(str_repeat($grapheme, 3), str_repeat($grapheme, 2), $offset);
+        }
+        echo $function, ': ', implode(', ', $positions), "\n";
+    }
+}
+
+var_dump(grapheme_strripos("\u{00C9}\u{00E9}\u{00C9}", "\u{00E9}\u{00E9}", -1));
+var_dump(grapheme_strrpos("\u{00E9}\u{00E9}x\u{00E9}\u{00E9}", "\u{00E9}\u{00E9}", -1));
+var_dump(grapheme_strrpos("\u{00E9}\u{00E9}x\u{00E9}\u{00E9}", "\u{00E9}\u{00E9}", -3));
+?>
+--EXPECT--
+grapheme_strrpos: 1, 1, 1, 1, 0
+grapheme_strripos: 1, 1, 1, 1, 0
+grapheme_strrpos: 1, 1, 1, 1, 0
+grapheme_strripos: 1, 1, 1, 1, 0
+grapheme_strrpos: 1, 1, 1, 1, 0
+grapheme_strripos: 1, 1, 1, 1, 0
+grapheme_strrpos: 1, 1, 1, 1, 0
+grapheme_strripos: 1, 1, 1, 1, 0
+int(1)
+int(3)
+int(0)