Skip to content
Merged
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:
Comment thread
lacatoire marked this conversation as resolved.
. ftp_nb_fget(), ftp_nb_fput(), ftp_nb_get() and ftp_nb_put() now throw an
Error when the connection is already transferring, instead of emitting a
warning and returning false. 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
16 changes: 8 additions & 8 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 @@ -771,8 +771,8 @@ PHP_FUNCTION(ftp_nb_get)
}
GET_FTPBUF(ftp, z_ftp);
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();
}
XTYPE(xtype, mode);

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 Expand Up @@ -1107,8 +1107,8 @@ PHP_FUNCTION(ftp_nb_put)

if (ftp->in_use) {
php_stream_close(instream);
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();
}

/* configuration */
Expand Down
11 changes: 10 additions & 1 deletion ext/ftp/tests/ftp_nb_get_during_nb_transfer.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ require 'server.inc';
class NbGetDuringNbGet {
public $context;
public static $ftp;
public static $error;
public function stream_open($path, $mode, $options, &$opened_path) {
return true;
}
public function stream_write($data) {
@ftp_nb_get(self::$ftp, 'php://memory', 'a story.txt', FTP_BINARY);
try {
ftp_nb_get(self::$ftp, 'php://memory', 'a story.txt', FTP_BINARY);
} catch (Throwable $e) {
/* recorded rather than echoed: stream_write() may run more than once */
self::$error = $e::class . ': ' . $e->getMessage();
}
return strlen($data);
}
public function stream_close() {}
Expand All @@ -35,10 +41,13 @@ while ($r == FTP_MOREDATA) {
}
var_dump($r === FTP_FINISHED);

var_dump(NbGetDuringNbGet::$error);

ftp_close($ftp);
echo "closed\n";
?>
--EXPECT--
bool(true)
bool(true)
string(68) "Error: Cannot start a transfer while another transfer is in progress"
closed
11 changes: 10 additions & 1 deletion ext/ftp/tests/ftp_nb_get_during_transfer.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ require 'server.inc';
class NbGetDuringGet {
public $context;
public static $ftp;
public static $error;
public function stream_open($path, $mode, $options, &$opened_path) {
return true;
}
public function stream_write($data) {
@ftp_nb_get(self::$ftp, 'php://memory', 'a story.txt', FTP_BINARY);
try {
ftp_nb_get(self::$ftp, 'php://memory', 'a story.txt', FTP_BINARY);
} catch (Throwable $e) {
/* recorded rather than echoed: stream_write() may run more than once */
self::$error = $e::class . ': ' . $e->getMessage();
}
return strlen($data);
}
public function stream_close() {}
Expand All @@ -31,10 +37,13 @@ NbGetDuringGet::$ftp = $ftp;

var_dump(@ftp_get($ftp, 'reentrantget://sink', 'a story.txt', FTP_BINARY));

var_dump(NbGetDuringGet::$error);

ftp_close($ftp);
echo "closed\n";
?>
--EXPECT--
bool(true)
bool(true)
string(68) "Error: Cannot start a transfer while another transfer is in progress"
closed
67 changes: 67 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,67 @@
--TEST--
ftp_nb_fget(), ftp_nb_fput(), ftp_nb_get() and ftp_nb_put() 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 (Throwable $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+');
/* ftp_nb_put() opens the local file before it reaches the guard, so it has to exist. */
$local = __DIR__ . '/ftp_nb_transfer_during_transfer.tmp';
file_put_contents($local, 'payload');

$calls = [
static fn ($ftp) => ftp_nb_fget($ftp, $sink, 'a story.txt', FTP_BINARY),
static fn ($ftp) => ftp_nb_fput($ftp, 'a story.txt', $sink, FTP_BINARY),
static fn ($ftp) => ftp_nb_get($ftp, $local, 'a story.txt', FTP_BINARY),
static fn ($ftp) => ftp_nb_put($ftp, 'a story.txt', $local, FTP_BINARY),
];

foreach ($calls as $call) {
TransferDuringNbWrite::$call = $call;
@ftp_nb_get($ftp, 'reentrantnb://sink', 'a story.txt', FTP_BINARY);
}

ftp_close($ftp);
echo "closed\n";
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/ftp_nb_transfer_during_transfer.tmp');
?>
--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
Error: Cannot start a transfer while another transfer is in progress
Error: Cannot start a transfer while another transfer is in progress
closed
Loading