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
2 changes: 1 addition & 1 deletion ext/ftp/ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t pat
#else
while (e > ptr && (s = memchr(ptr, '\r', (e - ptr)))) {
php_stream_write(outstream, ptr, (s - ptr));
if (*(s + 1) == '\n') {
if (s + 1 < e && *(s + 1) == '\n') {
s++;
php_stream_putc(outstream, '\n');
}
Expand Down
25 changes: 25 additions & 0 deletions ext/ftp/tests/ftp_get_ascii_crlf_boundary.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
ftp_get() ASCII mode: CRLF straddling the FTP_BUFSIZE read boundary
--EXTENSIONS--
ftp
pcntl
--FILE--
<?php
require 'server.inc';

$ftp = ftp_connect('127.0.0.1', $port);
ftp_login($ftp, 'user', 'pass');
$ftp or die("Couldn't connect to the server");

$local = __DIR__ . "/crlf_boundary_out.txt";

var_dump(ftp_get($ftp, $local, 'crlf_boundary', FTP_ASCII));
var_dump(file_get_contents($local) === str_repeat("A", 4095) . "\n" . str_repeat("B", 10));
?>
--CLEAN--
<?php
@unlink(__DIR__ . "/crlf_boundary_out.txt");
?>
--EXPECT--
bool(true)
bool(true)
7 changes: 7 additions & 0 deletions ext/ftp/tests/server.inc
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,13 @@ if ($pid) {
// Just a side channel for getting the received file size.
fputs($s, "425 Can't open data connection (".$GLOBALS['rest_pos'].").\r\n");
break;
case "crlf_boundary":
// A CRLF whose CR lands on the final byte of the first
// FTP_BUFSIZE (4096) read, so the LF arrives in the next read.
fputs($s, "150 File status okay; about to open data connection.\r\n");
fputs($fs, str_repeat("A", 4095) . "\r\n" . str_repeat("B", 10));
fputs($s, "226 Closing data Connection.\r\n");
break;

default:
fputs($s, "550 {$matches[1]}: No such file or directory \r\n");
Expand Down
Loading