Skip to content

ext/intl: Reject truncated lengths in UConverter::setSubstChars() - #25708

Merged
LamentXU123 merged 1 commit into
php:masterfrom
LamentXU123:intl-84-uconverter-subst-chars
Nov 24, 2026
Merged

LamentXU123 merged 1 commit into
php:masterfrom
LamentXU123:intl-84-uconverter-subst-chars

Conversation

@LamentXU123

Copy link
Copy Markdown
Member
<?php
$c = new UConverter('US-ASCII', 'UTF-8');
var_dump($c->setSubstChars(str_repeat('X', 257)));

should be bool(false), but now the 257 'X's are truncated to 1 'X' so its true 😂

Originally reported by @wwkenwong

@iliaal iliaal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a reason to target PHP-8.4 here? GH-22199 targeted master and added an UPGRADING entry for the same length truncation in UConverter::transcode(). This setter also changes some previously successful calls to return false. I’d target master for consistency and reuse php_converter_set_subst_chars() there.

Comment thread ext/intl/converter/converter.c Outdated

intl_errors_reset(&objval->error);

if (UNEXPECTED(chars_len > INT8_MAX)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With new UConverter('invalid-charset-name', 'UTF-8'), a 128-byte substitution already returns false on PHP-8.4. This early return changes getErrorCode() from U_INVALID_STATE_ERROR to U_ILLEGAL_ARGUMENT_ERROR. Please check the length inside the existing src and dest branches so the uninitialized destination keeps its diagnostic.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh wow good catch ;)

@LamentXU123
LamentXU123 marked this pull request as draft November 24, 2026 16:57
@LamentXU123
LamentXU123 force-pushed the intl-84-uconverter-subst-chars branch from 613e0c8 to a8a5c30 Compare November 24, 2026 16:58
@LamentXU123
LamentXU123 changed the base branch from PHP-8.4 to master November 24, 2026 16:58
@LamentXU123
LamentXU123 marked this pull request as ready for review November 24, 2026 16:58
@LamentXU123
LamentXU123 requested a review from iliaal November 24, 2026 16:58

@iliaal iliaal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the fixes, looks good now

@LamentXU123

Copy link
Copy Markdown
Member Author

Thanks for reviewing.

@LamentXU123
LamentXU123 merged commit 9081bad into php:master Nov 24, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants