[php-src] PR #22427: Fix int32_t overflow in intl_charFromString() capacity calculation
| From: | iliaal | Date: | Wed, 24 Jun 2026 11:22:15 +0000 |
| Subject: | [php-src] PR #22427: Fix int32_t overflow in intl_charFromString() capacity calculation | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-36593@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/22427
Author: iliaal
intl_charFromString() computed the UTF-8 output capacity as from.length() * 3 in int32_t arithmetic.
For a UnicodeString longer than INT32_MAX/3 UTF-16 code units the multiply overflows: capacity can
go negative (zend_string_alloc() then requests a near-SIZE_MAX block) or wrap small, undersizing the
buffer that u_strToUTF8WithSub() writes into. Reject the over-long input with
U_BUFFER_OVERFLOW_ERROR up front, mirroring the INT32_MAX guard already present in the sibling
intl_stringFromChar(). The input is always ICU-produced output, so triggering needs a multi-GB
UnicodeString; there is no portable red/green test, and the fix matches the project's
symmetric-path convention.