Skip to content

Custom stream wrapper dir_readdir output truncated to 255 characters in PHP 8.3 #14930

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

Closed
joec4i opened this issue Jul 12, 2024 · 7 comments
Closed

Comments

@joec4i
Copy link
Contributor

joec4i commented Jul 12, 2024

Description

The following code:

class DummyWrapper
{
    public $context;
    public const TEST_FILENAME = 'ieNoquiaC6ijeiy9beejaiphoriejo2cheehooGou8uhoh7eh0gefahyuQuohd7eec9auso9eeFah2Maedohsemi1eetoo5fo5biePh5eephai7SiuguipouLeemequ2oope9aigoQu5efak2aLeri9ithaiJ9eew3dianaiHoo1aexaighiitee6geghiequ5nohhiikahwee8ohk2Soip2Aikeithohdeitiedeiku7DiTh2eep3aiyeejair4dau4osai1si9laeZaiquoopomomai5eeMoce0oecietu';

    public function dir_opendir()
    {
        return true;
    }

    public function dir_readdir()
    {
        return self::TEST_FILENAME;
    }
}


stream_wrapper_register('dummy', 'DummyWrapper');

$dh = opendir('dummy://', stream_context_create());
$file = readdir($dh);

var_dump($file);
var_dump(DummyWrapper::TEST_FILENAME);

Resulted in this output:

➜  /tmp php stream_wrapper.php
/private/tmp/stream_wrapper.php:25:
string(255) "ieNoquiaC6ijeiy9beejaiphoriejo2cheehooGou8uhoh7eh0gefahyuQuohd7eec9auso9eeFah2Maedohsemi1eetoo5fo5biePh5eephai7SiuguipouLeemequ2oope9aigoQu5efak2aLeri9ithaiJ9eew3dianaiHoo1aexaighiitee6geghiequ5nohhiikahwee8ohk2Soip2Aikeithohdeitiedeiku7DiTh2eep3aiyeejair"
/private/tmp/stream_wrapper.php:26:
string(300) "ieNoquiaC6ijeiy9beejaiphoriejo2cheehooGou8uhoh7eh0gefahyuQuohd7eec9auso9eeFah2Maedohsemi1eetoo5fo5biePh5eephai7SiuguipouLeemequ2oope9aigoQu5efak2aLeri9ithaiJ9eew3dianaiHoo1aexaighiitee6geghiequ5nohhiikahwee8ohk2Soip2Aikeithohdeitiedeiku7DiTh2eep3aiyeejair4dau4osai1si9laeZaiquoopomomai5eeMoce0oecietu"
➜  /tmp php -v
PHP 8.3.9 (cli) (built: Jul  2 2024 14:10:14) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.9, Copyright (c) Zend Technologies
    with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans
    with Zend OPcache v8.3.9, Copyright (c), by Zend Technologies

But I expected this output instead:

➜  /tmp /opt/homebrew/Cellar/[email protected]/8.2.21/bin/php stream_wrapper.php
/private/tmp/stream_wrapper.php:25:
string(300) "ieNoquiaC6ijeiy9beejaiphoriejo2cheehooGou8uhoh7eh0gefahyuQuohd7eec9auso9eeFah2Maedohsemi1eetoo5fo5biePh5eephai7SiuguipouLeemequ2oope9aigoQu5efak2aLeri9ithaiJ9eew3dianaiHoo1aexaighiitee6geghiequ5nohhiikahwee8ohk2Soip2Aikeithohdeitiedeiku7DiTh2eep3aiyeejair4dau4osai1si9laeZaiquoopomomai5eeMoce0oecietu"
/private/tmp/stream_wrapper.php:26:
string(300) "ieNoquiaC6ijeiy9beejaiphoriejo2cheehooGou8uhoh7eh0gefahyuQuohd7eec9auso9eeFah2Maedohsemi1eetoo5fo5biePh5eephai7SiuguipouLeemequ2oope9aigoQu5efak2aLeri9ithaiJ9eew3dianaiHoo1aexaighiitee6geghiequ5nohhiikahwee8ohk2Soip2Aikeithohdeitiedeiku7DiTh2eep3aiyeejair4dau4osai1si9laeZaiquoopomomai5eeMoce0oecietu"
➜  /tmp /opt/homebrew/Cellar/[email protected]/8.2.21/bin/php -v
PHP 8.2.21 (cli) (built: Jul  2 2024 12:51:54) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.21, Copyright (c) Zend Technologies
    with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans
    with Zend OPcache v8.2.21, Copyright (c), by Zend Technologies

PHP Version

PHP 8.3.9

Operating System

Reproducible on both macOS and Debian Buster / Bookworm.

@joec4i
Copy link
Contributor Author

joec4i commented Jul 12, 2024

This was likely due to 00c1e7b . Since the change could break existing code, any chance if we can revert it or find a way to make it backward compatible? In our case, we have a legacy custom stream wrapper that returns a json string from dir_readdir(). It's a bad idea but I imagine there could be similarly weird use cases in other PHP apps that could hit this.
cc @nielsdos

@nielsdos
Copy link
Member

nielsdos commented Jul 12, 2024

I'm fine with simply reverting it. Cc @bukka
For reference, the commit was part of #11577

@bukka
Copy link
Member

bukka commented Jul 12, 2024

Yeah agreed, we should revert it.

@bukka
Copy link
Member

bukka commented Jul 12, 2024

It would be good to also add a test for this so we don't break it again in the future.

@joec4i
Copy link
Contributor Author

joec4i commented Jul 12, 2024

Thanks @nielsdos and @bukka . Please let me know if you want me to open a new PR with the test cases.

@nielsdos
Copy link
Member

Thanks @nielsdos and @bukka . Please let me know if you want me to open a new PR with the test cases.

Please do! :)

nielsdos added a commit that referenced this issue Jul 12, 2024
* PHP-8.3:
  Fix GH-14930: Custom stream wrapper dir_readdir output truncated to 255 characters in PHP 8.3
bukka added a commit to bukka/php-src that referenced this issue Aug 21, 2024
bukka added a commit to bukka/php-src that referenced this issue Aug 21, 2024
@bukka
Copy link
Member

bukka commented Aug 22, 2024

Just for the info, this got reverted from 8.3 because it was a serious ABI break that caused crashes in some extensions. It is kept only in master and will be part of PHP 8.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants