[php-src] Issue #8211: Segment fault 11 when trying to catch exception

From: Date: Thu, 17 Mar 2022 09:25:12 +0000
Subject: [php-src] Issue #8211: Segment fault 11 when trying to catch exception
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-240379@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8211 Author: madmortigan1 ### Description Hello, There is a very specific scenario which I know to explain how to reproduce but not to explain why it happens. I will do my best to explain below: Using Symfony version 6 only platform: using ``set_error_handler`, and using `include <file>`` that does not exists multiple times throws a Segment 11 error which I could not trace and explain what it means. This happens only on specific scenario, since doing a loop always catches it. I would like to add that this happens only on docker environment and does not happen on a normal php server. I have tried and it reproduces on alpine and debian containers. To simplify the explanation they use set_error_handler with the following function: ```$this->includeHandler = static function ($type, $msg, $file, $line) { throw new \ErrorException($msg, 0, $type, $file, $line); };``` The code runs with it is: ``` set_error_handler($this->includeHandler); try { foreach ($this->scanHashDir($this->directory) as $file) { try { if (\is_array($expiresAt = include $file)) { // <----- This is the problametic line [include...] $expiresAt = $expiresAt[0]; } } catch (\ErrorException $e) { $expiresAt = $time; } if ($time >= $expiresAt) { $pruned = $this->doUnlink($file) && !file_exists($file) && $pruned; } } } finally { restore_error_handler(); } ``` This will actually catch the error for a dozen of times and than throws the segment fault. I have a ready project with explanation which file it is happening in and how to reproduce it. [Reproduce github link](https://github.com/madmortigan1/symfony-cache) There is also a link for this in Symfony community: [Here](https://github.com/symfony/symfony/issues/44954) ### PHP Version php 8.1.3 ### Operating System Docker container php:8.1-fpm latest

« previous php.bugs (#240379) next »