Test case to reproduce a PHP segmentation fault involving Xdebug, streams, and dates

Overview

The code in this repository causes a segmentation fault when run with PHP 8.0.6 on Fedora 33.

This issue was originally reported to the Xdebug project for further investigation, which lead to the discovery of a bug in PHP core. Thanks to @derickr for this commit, which should address the issue in future releases of the 7.4, 8.0, and 8.1 branches.

Installation

  1. Install dependencies.

    composer install
  2. Run the script.

    php index.php

Root Cause

Uncommenting the closedir() call near the end of index.php avoids the segmentation fault, so this presumably only happens on shutdown when the directory handle is left open, causing StreamWrapper->dir_closedir() to be implicitly invoked.

Uncommenting the xdebug_start_trace() call at the end of the script produces the trace in xdebug.xt. In particular, line 9 appears to indicate that the timezone is being corrupted in memory at some point.

0.0091     450976         -> Monolog\DateTimeImmutable->__construct($useMicroseconds = TRUE, $timezone = class DateTimeZone { public $time    zone_type = 3; public $timezone = 'À<83>çDJ^?' }) /home/matt/Code/Personal/sandbox/vendor/monolog/monolog/src/Monolog/Logger.php:309

Adding var_dump($this->timezone); to the bottom of __construct() in vendor/monolog/monolog/src/Monolog/Logger.php produces the expected output for my system.

vendor/monolog/monolog/src/Monolog/Logger.php:163:
class DateTimeZone#4 (2) {
  public $timezone_type =>
  int(3)
  public $timezone =>
  string(15) "America/Chicago"
}

Doing the same at the start of addRecord() (see line 6 in xdebug.xt) indicates that $this->timezone is corrupt at that point.

/home/matt/Code/Personal/sandbox/vendor/monolog/monolog/src/Monolog/Logger.php:292:
class DateTimeZone#4 (2) {
  public $timezone_type =>
  int(3)
  public $timezone =>
  string(6) "��g"
}

GDB Backtrace

A segmentation fault occurs regardless of whether the conditions listed below are present. However, gdb has no available stack trace unless the conditions are met.

  1. Xdebug is loaded
  2. The xdebug_start_trace() at the bottom of index.php is uncommented.
  3. xdebug.mode / XDEBUG_MODE is set to trace.

Without these conditions:

$ gdb php
GNU gdb (GDB) Fedora 10.2-1.fc33
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from php...
Reading symbols from /usr/lib/debug/usr/bin/php-8.0.6-1.fc33.remi.x86_64.debug...
(gdb) run index.php
Starting program: /usr/bin/php index.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[Inferior 1 (process 33184) exited with code 01]
Missing separate debuginfos, use: dnf debuginfo-install php-pecl-xdebug3-3.0.4-1.fc33.remi.8.0.x86_64
(gdb) bt
No stack.

With these conditions:

$ XDEBUG_MODE=trace gdb php
GNU gdb (GDB) Fedora 10.2-1.fc33
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from php...
Reading symbols from /usr/lib/debug/usr/bin/php-8.0.6-1.fc33.remi.x86_64.debug...
(gdb) run index.php
Starting program: /usr/bin/php index.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x0000555555665dc7 in fetch_timezone_offset (tz=tz@entry=0x7ffff7278280, ts=ts@entry=1626524012,
    transition_time=transition_time@entry=0x7fffffffa6f0) at /usr/src/debug/php-8.0.6-1.fc33.remi.x86_64/ext/date/lib/parse_tz.c:1153
1153		if (ts < tz->trans[0]) {
Missing separate debuginfos, use: dnf debuginfo-install php-pecl-xdebug3-3.0.4-1.fc33.remi.8.0.x86_64

See gdb.log for a copy of the stack trace.

You might also like...
Allow multiple options for Magento 2 checkout layout. Provides capabilities to AB test checkout changes and more.
Allow multiple options for Magento 2 checkout layout. Provides capabilities to AB test checkout changes and more.

Aimes_CheckoutDesigns Features Please note: This module is currently still considered a proof of concept. This module provides the ability to change c

A Laravel test build by Incline Start-up Agency. Testing Git and framework functions.

Incognito-Confessions A laravel test build by Incline Start-up Agency. Testing Git and framework functions. Description A laravel starter for future t

Samsui is a factory library for building PHP objects useful for setting up test data in your applications.

#Samsui Samsui is a factory library for building PHP objects useful for setting up test data in your applications. It is mainly inspired by Rosie for

Test essentials for writing testable code that interacts with Magento core modules

Essentials for testing Magento 2 modules Using mocking frameworks for testing Magento 2 modules is counterproductive as you replicate line by line you

Test with laravel framework

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Contains a few tools usefull for making your test-expectations agnostic to operating system specifics

PHPUnit Tools to ease cross operating system Testing make assertEquals* comparisons end-of-line (aka PHP_EOL) character agnostic Make use of EolAgnost

The full-stack test project for Personnel LTD.
The full-stack test project for Personnel LTD.

personnel-ltd The full-stack test project for Personnel LTD. Clone and install composer dependencies. $ git clone [email protected]:arsovskidev/personnel

⚓️ Easily test HTTP webhooks with this handy tool that displays requests instantly.

Webhook.site With Webhook.site, you instantly get a unique, random URL that you can use to test and debug Webhooks and HTTP requests, as well as to cr

This is a public repository developed to Mooven for test.

How to start First Step: Clone repository to your PC Second Step: Run the command: composer dumpautoload Third Step: IMPORTANT STEP! Now you have to c

Owner
Matthew Turland
spouse, parent, egalitarian, geek, tenor, author, speaker, software engineer, open source enthusiast, perpetually tired, he/him
Matthew Turland
PHP implementation for reading and writing Apache Parquet files/streams

php-parquet This is the first parquet file format reader/writer implementation in PHP, based on the Thrift sources provided by the Apache Foundation.

null 17 Oct 25, 2022
Magento 2 Debug Helper Module for easy debugging with Xdebug and PHPStorm or any other IDE

Magento 2 Debug Helper Information and Usage Magento 2 Debug Helper Module usage with PHPStorm and Xdebug Installation To install the Magento 2 Debug

Dmitry Shkoliar 13 May 24, 2022
Object-Oriented API for PHP streams

Streamer Streamer is an Object-Oriented API for PHP streams. Why should I use Streams? A stream is a flow of bytes from one container to the other. Yo

Francois Zaninotto 270 Dec 21, 2022
This packages enables the ability to serve file streams in a smart way

A blade component for easy image manipulation Want to serve private hosted images without the need to code your own logic ? Want to resize your images

Dieter Coopman 205 Dec 19, 2022
Dockerise Symfony Application (Symfony 6 + Clean Architecture+ DDD+ CQRS + Docker + Xdebug + PHPUnit + Doctrine ORM + JWT Auth + Static analysis)

Symfony Dockerise Symfony Application Install Docker Install Docker Compose Docker PHP & Nginx Create Symfony Application Debugging Install Xdebug Con

null 48 Jan 5, 2023
Generally, a graceful shutdown is preferable in the case of any OS that saves its state

Graceful Shutdown with PHP Generally, a graceful shutdown is preferable in the case of any OS that saves its state.

Leonardo Carmo 17 Oct 14, 2022
Enhancement to Magento to allow simple product prices to be used instead of the default special-case configurable product prices

Simple Configurable Products Extension For Magento This documentation applies to SCP versions 0.7 onwards. The documentation for SCP v0.6 and earlier

Simon King 288 Nov 7, 2022
Quickly and easily preview and test your Magento 2 order confirmation page, without hacks or spending time placing new order each time

Preview Order Confirmation Page for Magento 2 For Magento 2.0.x, 2.1.x, 2.2.x and 2.3.x Styling and testing Magento's order confirmation page can be a

MagePal :: Magento Extensions 71 Aug 12, 2022
Test and enforce architectural rules in your Laravel applications. Keep your app's architecture clean and consistent!

Laravel Arkitect Laravel Arkitect lets you test and enforce your architectural rules in your Laravel applications, and it's a PHPArkitect wrapper for

SMorteza Ebadi 55 Dec 17, 2022
A library for reading and writing DNA test kit files in PHP.

php-dna Requirements php-dna 1.0+ requires PHP 8.0 (or later). Installation There are two ways of installing php-dna. Composer To install php-dna in y

Family Tree 365 4 Aug 31, 2022