-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
preg_replace times out after upgrading to 8.2 when browscap setting is set #12885
Comments
Do you know if it crashes immediately, or on request shutdown? |
The browser shows it returning a 500 after 2.07 seconds. I'll give it a try on 8.2.4 tomorrow. |
So I'm actually not able to reproduce it with any of the pre-built Windows packages. I can only reproduce it with a custom one that we build. Here is the Configure Command:
|
To me it is unlikely related to the previous browscap issues or browscap at all as those took just effect when a call to |
It's a little bit more subtle. In your case the actual corruption happened during the parsing of the browscap file, but only became exposed when get_browser was actually called. It's however possible, depending on the heap layout, that it triggers even without a call to get_browser. Now, it could be possible of course that the browscap symptom in this issue is a red herring. @ymTm7KuhCnIjkZAl2x2m2 I tried to reproduce this on my Windows VM but I couldn't. Are you able to checkout the latest source of branch PHP-8.2 and build the latest version and test? |
Sorry I was unable to build the PHP-8.2 branch. |
Okay I was able to build both the PHP-8.2 branch (as of 3 days ago) and version 8.2.4 and they both have the same issue. |
Ok no regresion then from that change. |
And ofc when I press send I realise I misread your message... so it's not fixed and not a regression... bummer... |
Had to obfuscate some things and change html to txt. Also I built a version of 8.2.0 and the script worked on the first try and then not on subsequent attempts. |
I'm able to reproduce this issue with a single line and browscap not enabled.
Event viewer shows:
|
If I change pcre.recursion_limit to something smaller, it crashes half as often! |
Okay so here is an entire code block that I'm using to reproduce a regex crash. Without the $_SESSION code it doesn't seem to crash. With the code it crashes half of the time.
|
I've upgraded to the latest 8.2, I've upgraded to 8.3.3, I've removed --with-pcre-jit and --enable-mbregex and it still crashes. Preg_replace is just completely unusable. |
I can't reproduce this on Linux. I'm going to try a custom Windows build again like you did and check with ASAN. |
I can't reproduce it on Windows either and ASAN shows nothing. Try to compile a debug build, but change the following line in configure.js from: Check what the output is on crash. If you get nothing special, try setting the |
Okay! I think I've figured it out: When we were on 8.1.X, we couldn't use PCRE 10.39 because of vulnerabilities. Somebody noticed that 8.2.X had 10.40 so we updated our version and made two code changes to get 8.1 to run with 10.40. However, they took it from the master branch instead of any 8.2 branch. I see that 8.3 has been updated to PCRE 10.42. So I updated to that (8.3.3 branch) and everything works. So the real issue is that the master branch of PCRE is (or was?) in a weird state. For example, in php-src/ext/pcre/php_pcre.c, line 37 in the 8.3.3 branch is
While in master that line is absent. It seems like the master we used was randomly missing some 14 year old commits yet contained some from last year. Feel free to close the ticket, or use it to get master in line with whatever it should be. |
Glad that your issue is resolved! The master branch has PCRE2 10.43, and some other additions. So I can imagine there are some differences that could cause issues indeed.
I just checked and don't find anything odd. We also normally backport any critical bugs or vulnerability fixes from more recent pcre2 versions to lower stable versions of PHP that ship an older pcre2. |
Description
I had this issue after upgrading to 8.2 and I've created this example that shows the issue. My php.ini is exactly the production version with one change: browscap points to the latest lite_php_browscap.ini from browscap.org. I'm using IIS on Windows Server 2022.
The following code:
Resulted in this output:
But I expected this output instead:
In fact, I do get this output if I comment out the browscap setting in php.ini. I also get this result if I remove many lines from the browscap file. I did not see this issue in PHP 8.1.
PHP Version
8.2.13
Operating System
Windows Server 2022
The text was updated successfully, but these errors were encountered: