[php-src] PR #17404: Test: grapheme_extract should slide properly past error bytes.
| From: | dmsnell | Date: | Wed, 08 Jan 2025 11:10:16 +0000 |
| Subject: | [php-src] PR #17404: Test: grapheme_extract should slide properly past error bytes. | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-30304@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/17404
Author: dmsnell
Adds a test to assert that the
$next parameter of grapheme_extract()
points to the next byte offset in the input $haystack after accounting for the moved
offset, according to the docs:
> If offset does not point to the first byte of a UTF-8 character,
> the start position is moved to the next character boundary.
It seems that the existing behavior is to find the next grapheme boundary from the original provided
offset, but if the offset doesn’t point to a valid starting byte, the assigned $next
value will point to the byte that was immediately decoded in the same call, leading to possible
infinite loops in user-space code.
```
while ( $at < strlen( $s ) ) {
$grapheme = grapheme_extract( "\x85PHP", 1, GRAPHEME_EXTR_COUNT, $at, $at );
// never moves past the second byte, always returns 'P'
}
```