Skip to content

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

Closed

Description

@joec4i

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.

Activity

  1. joec4i commented on Jul 12, 2024

    @joec4i
    ContributorAuthor

    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

  2. ndossche commented on Jul 12, 2024

    @ndossche
    Member

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

  3. bukka commented on Jul 12, 2024

    @bukka
    Member

    Yeah agreed, we should revert it.

  4. bukka commented on Jul 12, 2024

    @bukka
    Member

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

  5. joec4i commented on Jul 12, 2024

    @joec4i
    ContributorAuthor

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

  6. ndossche commented on Jul 12, 2024

    @ndossche
    Member

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

    Please do! :)

  7. added a commit that references this issue on Jul 12, 2024
  8. added a commit that references this issue on Jul 12, 2024
    38501ed
  9. added a commit that references this issue on Jul 12, 2024
    3703459
  10. bukka commented on Aug 22, 2024

    @bukka
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions