Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ PHP 8.6 UPGRADE NOTES
the integer index is greater than INT_MAX instead of overflowing to a
smaller index.

- FTP:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong, but the original fix (that caused this return-type-mismatch issue) went into master-only right? If so, then instead of emitting a warning and returning false against their declared int return type. is confusing and can go away.

. ftp_nb_fget() and ftp_nb_fput() now throw an Error when the connection is
already transferring, instead of emitting a warning and returning false
against their declared int return type. ftp_close() already throws on the
same condition.

- GD:
. imagesetstyle(), imagefilter() and imagecrop() filter the types / values of
their array arguments and raise a TypeError / ValueError accordingly.
Expand Down
8 changes: 4 additions & 4 deletions ext/ftp/php_ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ PHP_FUNCTION(ftp_nb_fget)

/* configuration */
if (ftp->in_use) {
php_error_docref(NULL, E_WARNING, "FTP\\Connection is already in use");
RETURN_FALSE;
zend_throw_error(NULL, "Cannot start a transfer while another transfer is in progress");
RETURN_THROWS();
}

ftp->direction = 0; /* recv */
Expand Down Expand Up @@ -961,8 +961,8 @@ PHP_FUNCTION(ftp_nb_fput)

/* configuration */
if (ftp->in_use) {
php_error_docref(NULL, E_WARNING, "FTP\\Connection is already in use");
RETURN_FALSE;
zend_throw_error(NULL, "Cannot start a transfer while another transfer is in progress");
RETURN_THROWS();
}

ftp->direction = true; /* send */
Expand Down
56 changes: 56 additions & 0 deletions ext/ftp/tests/ftp_nb_transfer_during_transfer.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--TEST--
ftp_nb_fget() and ftp_nb_fput() throw when a transfer is already in progress
--EXTENSIONS--
ftp
pcntl
--FILE--
<?php
require 'server.inc';

class TransferDuringNbWrite {
public $context;
public static $ftp;
public static $call;
public function stream_open($path, $mode, $options, &$opened_path) {
return true;
}
public function stream_write($data) {
try {
(self::$call)(self::$ftp);
} catch (\Error $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
return strlen($data);
}
public function stream_close() {}
public function stream_eof() {
return true;
}
}

stream_wrapper_register('reentrantnb', TransferDuringNbWrite::class);

$ftp = ftp_connect('127.0.0.1', $port);
var_dump(ftp_login($ftp, 'user', 'pass'));
TransferDuringNbWrite::$ftp = $ftp;

$sink = fopen('php://memory', 'w+');

TransferDuringNbWrite::$call = static function ($ftp) use ($sink) {
ftp_nb_fget($ftp, $sink, 'a story.txt', FTP_BINARY);
};
@ftp_nb_get($ftp, 'reentrantnb://sink', 'a story.txt', FTP_BINARY);

TransferDuringNbWrite::$call = static function ($ftp) use ($sink) {
ftp_nb_fput($ftp, 'a story.txt', $sink, FTP_BINARY);
};
@ftp_nb_get($ftp, 'reentrantnb://sink', 'a story.txt', FTP_BINARY);

ftp_close($ftp);
echo "closed\n";
?>
--EXPECT--
bool(true)
Error: Cannot start a transfer while another transfer is in progress
Error: Cannot start a transfer while another transfer is in progress
closed