10000 Segment fault 11 when trying to catch exception · Issue #8211 · php/php-src · GitHub
[go: up one dir, main page]

Skip to content
Segment fault 11 when trying to catch exception #8211
@madmortigan1

Description

@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

There is also a link for this in Symfony community: Here

PHP Version

php 8.1.3

Operating System

Docker container php:8.1-fpm latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0