WP_Filesystem: Ensure that all files are read/written correctly by verifying the return values from fwrite() and using FTP_BINARY mode (ASCII converts line endings as per the spec). See #25237

git-svn-id: https://develop.svn.wordpress.org/trunk@25304 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse
2013-09-09 02:42:52 +00:00
parent d92f3ab536
commit 2f40784d97
4 changed files with 42 additions and 30 deletions
@@ -75,20 +75,16 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
return false;
}
$this->ftp->SetType(FTP_AUTOASCII);
$this->ftp->Passive(true);
$this->ftp->setTimeout(FS_TIMEOUT);
$this->ftp->SetType( FTP_BINARY );
$this->ftp->Passive( true );
$this->ftp->setTimeout( FS_TIMEOUT );
return true;
}
function get_contents($file, $type = '', $resumepos = 0) {
function get_contents( $file ) {
if ( ! $this->exists($file) )
return false;
if ( empty($type) )
$type = FTP_AUTOASCII;
$this->ftp->SetType($type);
$temp = wp_tempnam( $file );
if ( ! $temphandle = fopen($temp, 'w+') )
@@ -122,11 +118,14 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
return false;
}
fwrite($temphandle, $contents);
fseek($temphandle, 0); //Skip back to the start of the file being written to
$bytes_written = fwrite( $temphandle, $contents );
if ( false === $bytes_written || $bytes_written != strlen( $contents ) ) {
fclose( $temphandle );
unlink( $temp );
return false;
}
$type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
$this->ftp->SetType($type);
fseek( $temphandle, 0 ); // Skip back to the start of the file being written to
$ret = $this->ftp->fput($file, $temphandle);