Skip to content

ext/intl: Fix for the issue where strlen could potentially become negative #18477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ext/intl/grapheme/grapheme_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,10 @@ PHP_FUNCTION(grapheme_levenshtein)
int32_t strlen_1, strlen_2;
strlen_1 = grapheme_split_string(ustring1, ustring1_len, NULL, 0);
strlen_2 = grapheme_split_string(ustring2, ustring2_len, NULL, 0);
if (UNEXPECTED(strlen_1 < 0 || strlen_2 < 0)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before merging, and since that s the whole point of this PR. can you think of few test cases to trigger this code path ? Cheers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devnexen

Logically, it seems to return -1 when a bad status is received, just like in the following location.

However, I can’t think of a specific way to intentionally reproduce that behavior…

if (U_FAILURE(ustatus)) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried something simpler, grapheme_strlen except U_MEMORY_ALLOCATION_ERROR I can t think of cases as bad inputs are caught up before that.

RETVAL_FALSE;
goto out_ustring2;
}

if (strlen_1 == 0) {
RETVAL_LONG(strlen_2 * cost_ins);
Expand Down