php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73597 failed to open stream/dir: operation failed
Submitted: 2016-11-24 02:44 UTC Modified: -
Votes:43
Avg. Score:4.5 ± 0.7
Reproduced:43 of 43 (100.0%)
Same Version:13 (30.2%)
Same OS:12 (27.9%)
From: niko dot el dot gatito at gmail dot com Assigned:
Status: Open Package: ssh2 (PECL)
PHP Version: 5.6.28 OS: CentOS 7
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-11-24 02:44 UTC] niko dot el dot gatito at gmail dot com
Description:
------------
Multiple of our perfectly working scripts for years suddenly stopped working right after the automatic update to php 5.6.28. Reverting back to a php 5.5 version make everything work as it should again. sftp linux command is working perfectly, everything works as it should from any other environment (multiple tests done) etc. Right now everything points out php 5.6.28 to be the culprit.

It seems that SSH2 connects and even log in BUT there is not way to access ANY folder level even though access is granted and everything works fine with other php versions. 

Example of error thrown:
fopen(ssh2.sftp://Resource id #3/./): failed to open stream: operation failed in...
scandir(ssh2.sftp://Resource id #3/upload/): failed to open dir: operation failed in....
scandir(): (errno 11): Resource temporarily unavailable in...

This has caused us a headache and although sftp is maybe not the most popular protocol I'm surprise that we did not find any post regarding this issue online.

php released this version on Nov. 10th and our CPanel automatically updated on Nov. 15th. Since then our log clearly showed that all sftp connection were unable to feed.

Test script:
---------------
...

if ($connection = ssh2_connect($ftp_server, $ftp_port)) {
    echo "Connected to SFTP server.";
} else {
    echo "Can't connect to SFTP server.";
}
if (ssh2_auth_password($connection, $ftp_username, $ftp_password)) {
    echo "Logged to SFTP server.";
} else {
    echo "Can't log to SFTP server.";
}

$sftp = ssh2_sftp($connection);

$stream = fopen("ssh2.sftp://$sftp/./", 'r');

$files = array_diff(scandir('ssh2.sftp://' . $sftp . $ftp_dir), array('..', '.'));

echo "<pre>";
print_r($files);
echo "</pre>";

...


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-24 05:09 UTC] albertcasademont at gmail dot com
Same here but on PHP 7.0.13, was perfectly working before...
 [2016-11-24 05:35 UTC] albertcasademont at gmail dot com
I can confirm that this was working in PHP 7.0.9
 [2016-11-24 17:10 UTC] niko dot el dot gatito at gmail dot com
Finally it appears to be a known issue:

https://forum.remirepo.net/viewtopic.php?id=3509

As mentioned the above thread, they had to issue a patch for SSH2.

This is the security fix added in php 5.6.28 causing the issue:

https://bugs.php.net/bug.php?id=73192

It does not seem that the patch is yet available in the official SSH2 repo but can be found in the Remi repo below (SSH2 version 013-3):

https://rpms.remirepo.net/enterprise/7/php56/x86_64/repoview/php-pecl-ssh2.html
 [2016-11-24 18:57 UTC] perske at muenster dot de
Circumvention:

In place of:   'ssh2.sftp://' . $sftp         . '/...'
write:         'ssh2.sftp://' . intval($sftp) . '/...'
 [2016-11-24 23:20 UTC] niko dot el dot gatito at gmail dot com
I confirm that the quick fix solution provided by "perske at muenster dot de" is working fine. 

intval() has to be used on every directory access functions as:

fopen("ssh2.sftp://".intval($sftp)."/./", 'r');
scandir('ssh2.sftp://' . intval($sftp) . "/dir/");

Also worth mentioning that setting $sftp = intval($sftp) in advance won't work.
 [2016-12-20 12:29 UTC] ikonta at yandex dot ru
The same issue since php-5.6.28, followed in php-5.6.29 on EL7.
Referenced patch for php-pecl-ssh2-0.13 fixed it.
 [2017-05-02 12:05 UTC] pawel dot zegardlo at bm dot pl
When this fix is planned to be released in the stable version?
 [2017-07-18 01:50 UTC] eagleg at ciandt dot com
Mine php is 5.6.31 on ubuntu. Also has the same issue.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC