|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74831 opendir() over ssh2 works but triggers a segfault anyway (SFTP)
Submitted: 2017-06-29 15:09 UTC Modified: 2021-02-09 16:16 UTC
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: Assigned:
Status: Open Package: ssh2 (PECL)
PHP Version: 7.1.6 OS: Debian 8.8
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
New email:
PHP Version: OS:


 [2017-06-29 15:09 UTC]
When executing scripts, they work but the script ends with a "Segmentation fault".
This happens with php-7.1.6 as well as php-7.0.20, both using the ssh2-1.1.1.tgz release from
This does not happen when using php-5.6 with ssh2-0.13.tgz.

Test script:
$cfg_host = '';
$cfg_user = '';
$cfg_passwd = '';
$remote_folder = '';

$ssh_session = ssh2_connect($cfg_host);
if($ssh_session === FALSE) {
elseif(!ssh2_auth_password($ssh_session, $cfg_user, $cfg_passwd)) {
else {
  // ok

$sftp = ssh2_sftp($ssh_session);

if(ssh2_sftp_stat($sftp, $remote_folder) === FALSE) {
  // creating the folder is not in the scope of this script

$remote_path = sprintf('ssh2.sftp://%s/%s', $sftp, ltrim($remote_folder, '/'));
$folder = opendir($remote_path);

return; // segmentation fault

Expected result:
not a segfault

Actual result:
"Segmentation fault" is written to STDERR when the script ends. You can do a bunch of work after calling opendir() without any problems, though.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-29 19:32 UTC]
Calling closedir($folder) makes the problem go away.

See Elizabeth M. Smith's comment here:
 [2018-03-06 18:08 UTC] kweber at tccrocks dot com
Confirming that closedir($folder) solves this issue with PHP 7.1.15
 [2021-02-09 16:00 UTC]
-Assigned To: +Assigned To: cmb
 [2021-02-09 16:00 UTC]
I can only reproduce a segfault, if I call


If I call `closedir($folder)` before, I get another segfault, but
that one has already been reported as bug #79631.
 [2021-02-09 16:16 UTC]
-Assigned To: cmb +Assigned To:
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Sep 29 01:01:24 2023 UTC