[go: up one dir, main page]

Skip to content
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

Segmentation fault when converting immutable and mutable DateTime instances created using reflection #8471

Closed
hype09 opened this issue May 1, 2022 · 1 comment

Comments

@hype09
Copy link
hype09 commented May 1, 2022

Description

Reproduction

<?php

$reflection = new ReflectionClass('\DateTime');

$mutable = $reflection->newInstanceWithoutConstructor();
$immutable = \DateTimeImmutable::createFromMutable($mutable);

Resulted in this output:

Process exited with code 139.

https://3v4l.org/gg0dq

The segfault happens when converting an "incomplete" \DateTime to a \DateTimeImmutable instance and vice versa.

Background

I stumbled upon this during some unit test writing where my testing framework was unexpectedly mocking \DateTime objects for me. After debugging for a while I could narrow the cause down to the snippet above.

Solution

I'd love to attempt to provide a fix for this, but I am unsure as to the proper solution, implementation-wise: Should an error be thrown during the conversion, or during constructor-less creation of the reflection instance? Or maybe no errors at all and some "sane default" type of handling for creating DateTime instances via Reflection? Are there any precedents in the implementation for other internal classes in regards to this? Thanks in advance!

PHP Version

PHP 7.4 - PHP 8.1

Operating System

No response

@cmb69
Copy link
Member
cmb69 commented May 2, 2022

Should an error be thrown during the conversion, […]

I think so. It looks like DATE_CHECK_INITIALIZED() checks are missing in the mentioned methods.

derickr added a commit to derickr/php-src that referenced this issue May 5, 2022
…table DateTime instances created using reflection
@derickr derickr closed this as completed in 92f8f19 May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants