Repository navigation
Custom stream wrapper dir_readdir output truncated to 255 characters in PHP 8.3 #14930
Copy link
Copy link
Closed
Closed
Copy link
Description
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.
Reacted by Tom Arbesser
Activity
joec4i commentedon 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
ndossche commentedon Jul 12, 2024
I'm fine with simply reverting it. Cc @bukka
For reference, the commit was part of #11577
bukka commentedon Jul 12, 2024
Yeah agreed, we should revert it.
bukka commentedon 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 commentedon Jul 12, 2024
Thanks @nielsdos and @bukka . Please let me know if you want me to open a new PR with the test cases.
ndossche commentedon Jul 12, 2024
Please do! :)
phpGH-14930: Add test with long filename from custom stream wrapper
Fix GH-14930: Custom stream wrapper dir_readdir output truncated to 2…
Merge branch 'PHP-8.3'
bukka commentedon 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.