Skip to content

Forbid \C in UTF-8 patterns - #21139

Merged
arnaud-lb merged 4 commits into
php:PHP-8.4from
arnaud-lb:gh21134
Jul 27, 2026
Merged

Forbid \C in UTF-8 patterns#21139
arnaud-lb merged 4 commits into
php:PHP-8.4from
arnaud-lb:gh21134

Conversation

@arnaud-lb

@arnaud-lb arnaud-lb commented Feb 5, 2026

Copy link
Copy Markdown
Member

Possible fix for GH-21134.

\C results in undefined, potentially unsafe behavior in UTF-8 mode, so error out in case the escape sequence is used in UTF-8 mode.

@arnaud-lb
arnaud-lb changed the base branch from master to PHP-8.4 February 5, 2026 14:25
@arnaud-lb arnaud-lb changed the title Disable \C in UTF-8 patterns Forbid \C in UTF-8 patterns Feb 5, 2026
@arnaud-lb
arnaud-lb marked this pull request as ready for review February 5, 2026 18:45
Comment thread ext/pcre/php_pcre.c
coptions |= PCRE2_UCP;
#endif
/* The \C escape sequence is unsafe in PCRE2_UTF mode */
coptions |= PCRE2_NEVER_BACKSLASH_C;

@devnexen devnexen Feb 5, 2026

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.

would need to document it somehow (UPGRADING ?) wdyt ?

Comment thread ext/pcre/php_pcre.c Outdated
}
pcre2_get_error_message(errnumber, error, sizeof(error));
if (errnumber == PCRE2_ERROR_BACKSLASH_C_CALLER_DISABLED) {
strlcpy((char*)error, "using \\C is incompatible with the 'u' modifier", sizeof(error));

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.

yes the default message is a bit vague in this context, makes sense.

@devnexen

devnexen commented Feb 5, 2026

Copy link
Copy Markdown
Member

I know enough pcre2 to see it s LGTM but cc @ndossche just in case :)

Comment thread ext/pcre/php_pcre.c Outdated
@arnaud-lb

Copy link
Copy Markdown
Member Author

Thank you @devnexen @ndossche. Do feel it's reasonable to target 8.4 for this?

@ndossche

ndossche commented Feb 6, 2026

Copy link
Copy Markdown
Member

Since it can otherwise induce some potentially unsafe behaviour, I think 8.4 is reasonable.

@arnaud-lb

Copy link
Copy Markdown
Member Author

Thank you @devnexen @ndossche.

I figured that this may require the validation of @php/release-managers-84 @php/release-managers-85 too.

TL;DR:

  • Using \C in PCRE patterns in conjunction with the u modifier leads to memory unsafety
  • This PR forbids the use of \C in patterns with the u modifier, and targets PHP-8.4.

A quick grep of preg.*\\C in the top 18k composer package didn't find any use of \C.

@edorian

edorian commented Mar 25, 2026

Copy link
Copy Markdown
Member

No objection from my side.

I cut 8.5.5RC1 yesterday, but I'm happy to include this in 8.5.5 and take care of the communication if needed (Should the release be marked as a security release?)

And asking for the release announcement: Is there a workaround we recommend?

@arnaud-lb

Copy link
Copy Markdown
Member Author

Thank you @edorian.

A possible workaround would be to not use the u modifier on patterns with the \C escape sequence.

Regarding inclusion in 8.5.5: It would be nice but not absolutely necessary. It would make sense to also include the fix in 8.4.20 in this case. Either way is fine with me, I let you decide.

@edorian

edorian commented Mar 25, 2026

Copy link
Copy Markdown
Member

@arnaud-lb Great!

If @php/release-managers-84 are good with it as well I'm happy to go with the upcoming release.

Will you take of the merging into 8.5.5? Otherwises I'll cherrry-pick it after you've merged into 8.4 and up.

@edorian

edorian commented Apr 7, 2026

Copy link
Copy Markdown
Member

Update: Given I didn't hear from @php/release-managers-84, some private feedback from folks, and that the chance isn't in 8.4 yet I didn't want to cherry-pick it into 8.5.

So it'll go out with 8.5.6RC1 as a regular change.

@LamentXU123

Copy link
Copy Markdown
Member

I doubt you all forget this PR :) Is this mergeable now? @arnaud-lb

@arnaud-lb

Copy link
Copy Markdown
Member Author

Since we didn't hear from @php/release-managers-84, I'm going to merge this in master only, soon

@arnaud-lb
arnaud-lb changed the base branch from PHP-8.4 to master July 24, 2026 10:45
@NattyNarwhal

Copy link
Copy Markdown
Member

Sorry I didn't see the email earlier, this seems OK to me if 8.5 RMs are also OK with it.

@DanielEScherzer DanielEScherzer 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.

No objections from 8.5 RMs
RM approval for including in 8.5, technical review not performed

@arnaud-lb
arnaud-lb changed the base branch from master to PHP-8.4 July 27, 2026 08:08
@arnaud-lb
arnaud-lb merged commit 1b091dc into php:PHP-8.4 Jul 27, 2026
18 checks passed
arnaud-lb added a commit that referenced this pull request Jul 27, 2026
* PHP-8.5:
  Forbid \C in UTF-8 patterns (#21139)
NickSdot pushed a commit to NickSdot/php__php-src that referenced this pull request Jul 27, 2026
* PHP-8.4:
  Forbid \C in UTF-8 patterns (php#21139)
@arnaud-lb
arnaud-lb deleted the gh21134 branch July 27, 2026 17:12
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.

8 participants