You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PHP 8.2.0 access violation while executing a 'foreach' loop #10067
Encountered an access violation bug in PHP 8.2.0 while executing a foreach loop on an array. It's inside a complex PHP application. Unfortunateley, I cannot reproduce the error with a small extract of the code just with the loop. Using the extract, it works :-\
I added the extract also to here. But, might not help much as it works. I assigned the variables for the loop with the same values just before the loop which crashes. Background: Application is a house automation server. Loop creates the commands for an i2c command.
What I see:
The loop just stops before all array elements are executed and PHP exits immediately without calling any error- or exit-handler. The last command in the loop is executed. The next element is not retrieved. The loop is successfully executed ~10 times. In the next attempt, PHP crashes
No message is written to the prompt
No entry in the PHP error log is created (all error reporting is enabled)
A windows access violation event is created. See attachment (partly in German; hope thats not a problem)
It workes without errors in PHP 8.1.13 (cli) (built: Nov 22 2022 15:49:14) (ZTS Visual C++ 2019 x64)
If I can provide more information, just advise me.
Also, do you have OPcache enabled? If so, is JIT enabled? If so, please provide the settings (opcache.jit*). And try without JIT and even without OPcache.
Okay, so this is obviously a JIT issue, and as such a stack backtrace may not be helpful anyway.
PHP 8.2.0 (cli) (built: Dec 6 2022 15:31:23) (ZTS Visual C++ 2019 x64)
Do you have a particular reason to use a ZTS version? Are you actually using some multi-threading capabilities (such as provided by ext/parallel)? If not, please try an NTS build of PHP.
NTS 8.2.0 shows same behaviour as ZTS. Crashes in the 'foreach' loop with JIT enabled. Works with JIT disabled. Do you think the original crash dumps help? ~330 MB each.
And no, no specific reason why I use ZTS. I use it since ever. Reason possibly is that "thread safe" sounds better than "non thread safe" :-)
This looks very similar to #10626. That issue was about predicted empty arrays and foreach loops causing a segfault. This was fixed in 8.2.4 and above. Given that the code you posted has both an empty check and foreach loop, I think this might be the same issue and may be fixed as well.
Could you try version 8.2.4 and see if that fixes your problem? Thanks.
Activity
cmb69 commentedon Dec 8, 2022
Can you please try to generate a stack backtrace?
Also, do you have OPcache enabled? If so, is JIT enabled? If so, please provide the settings (
opcache.jit*). And try without JIT and even without OPcache.mdrmdrmdr commentedon Dec 8, 2022
Seems to work for 8.2.0 with OPcache disabled 😉
Had this settings in 8.2.0 and 8.1.13:
Stack backtrace analysis is attached.
MultipleDumps_MultipleRules.zip
Update:
Works also with OPcache enabled but JIT disabled!
mdrmdrmdr commentedon Dec 10, 2022
Anything more I can provide?
cmb69 commentedon Dec 10, 2022
That's not really helpful.
Okay, so this is obviously a JIT issue, and as such a stack backtrace may not be helpful anyway.
Do you have a particular reason to use a ZTS version? Are you actually using some multi-threading capabilities (such as provided by ext/parallel)? If not, please try an NTS build of PHP.
mdrmdrmdr commentedon Dec 10, 2022
NTS 8.2.0 shows same behaviour as ZTS. Crashes in the 'foreach' loop with JIT enabled. Works with JIT disabled. Do you think the original crash dumps help? ~330 MB each.
And no, no specific reason why I use ZTS. I use it since ever. Reason possibly is that "thread safe" sounds better than "non thread safe" :-)
cmb69 commentedon Dec 12, 2022
Maybe for someone accustomed to JIT, but even then it might be almost impossible to debug on Windows.
NTS is supposed to be a wee bit faster, and if you don't need multi-threading, it's usually recommendable.
DevSysEngineer commentedon Dec 14, 2022
Dear all,
We have exactly the same issue right now.
This code crashes PHP without any log:
When I changed this code to modern version, the code will run without any problems.
mdrmdrmdr commentedon Dec 15, 2022
Now I found out that I need ZTS. I'm running a local Apache installation. And it seems that NTS does not come with php8apache2_4.dll.
Same here. Once I change the loop element to "access by reference", the loop does not crash PHP anymore.
ndossche commentedon Mar 25, 2023
This looks very similar to #10626. That issue was about predicted empty arrays and foreach loops causing a segfault. This was fixed in 8.2.4 and above. Given that the code you posted has both an empty check and foreach loop, I think this might be the same issue and may be fixed as well.
Could you try version 8.2.4 and see if that fixes your problem? Thanks.
mdrmdrmdr commentedon Mar 25, 2023
Dug up the old code from my NAS backup. The crash still occurs with PHP 8.2.4 64Bit ZTS on Windows.
This one crashes (in the loop modifing the iterable_expression by val "$execs[$k][1]" ):
This one works fine (in the loop modifing the value by ref "$exec[1]"):