Make use of the mbstring.func_overload helper functions in WP_Filesystem so byte lengths are properly determined. See #25259 Fixes #25237

Built from https://develop.svn.wordpress.org/trunk@25349


git-svn-id: http://core.svn.wordpress.org/trunk@25311 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2013-09-11 08:27:10 +00:00
parent c93eb27bb2
commit 26ebfca466
3 changed files with 39 additions and 3 deletions

View File

@ -68,11 +68,17 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
if ( ! $fp ) if ( ! $fp )
return false; return false;
mbstring_binary_safe_encoding();
$data_length = strlen( $contents );
$bytes_written = fwrite( $fp, $contents ); $bytes_written = fwrite( $fp, $contents );
reset_mbstring_encoding();
fclose( $fp ); fclose( $fp );
if ( false === $bytes_written || $bytes_written != strlen( $contents ) ) if ( $data_length !== $bytes_written )
return false; return false;
$this->chmod( $file, $mode ); $this->chmod( $file, $mode );

View File

@ -118,8 +118,14 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
if ( ! $temp ) if ( ! $temp )
return false; return false;
mbstring_binary_safe_encoding();
$data_length = strlen( $contents );
$bytes_written = fwrite( $temp, $contents ); $bytes_written = fwrite( $temp, $contents );
if ( false === $bytes_written || $bytes_written != strlen( $contents ) ) {
reset_mbstring_encoding();
if ( $data_length !== $bytes_written ) {
fclose( $temp ); fclose( $temp );
unlink( $tempfile ); unlink( $tempfile );
return false; return false;

View File

@ -89,12 +89,19 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
if ( ! $temphandle = fopen($temp, 'w+') ) if ( ! $temphandle = fopen($temp, 'w+') )
return false; return false;
mbstring_binary_safe_encoding();
if ( ! $this->ftp->fget($temphandle, $file) ) { if ( ! $this->ftp->fget($temphandle, $file) ) {
fclose($temphandle); fclose($temphandle);
unlink($temp); unlink($temp);
reset_mbstring_encoding();
return ''; // Blank document, File does exist, It's just blank. return ''; // Blank document, File does exist, It's just blank.
} }
reset_mbstring_encoding();
fseek( $temphandle, 0 ); // Skip back to the start of the file being written to fseek( $temphandle, 0 ); // Skip back to the start of the file being written to
$contents = ''; $contents = '';
@ -117,10 +124,16 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
return false; return false;
} }
// The FTP class uses string functions internally during file download/upload
mbstring_binary_safe_encoding();
$bytes_written = fwrite( $temphandle, $contents ); $bytes_written = fwrite( $temphandle, $contents );
if ( false === $bytes_written || $bytes_written != strlen( $contents ) ) { if ( false === $bytes_written || $bytes_written != strlen( $contents ) ) {
fclose( $temphandle ); fclose( $temphandle );
unlink( $temp ); unlink( $temp );
reset_mbstring_encoding();
return false; return false;
} }
@ -128,6 +141,8 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
$ret = $this->ftp->fput($file, $temphandle); $ret = $this->ftp->fput($file, $temphandle);
reset_mbstring_encoding();
fclose($temphandle); fclose($temphandle);
unlink($temp); unlink($temp);
@ -293,9 +308,15 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
$limit_file = false; $limit_file = false;
} }
mbstring_binary_safe_encoding();
$list = $this->ftp->dirlist($path); $list = $this->ftp->dirlist($path);
if ( empty($list) && !$this->exists($path) ) if ( empty( $list ) && ! $this->exists( $path ) ) {
reset_mbstring_encoding();
return false; return false;
}
$ret = array(); $ret = array();
foreach ( $list as $struc ) { foreach ( $list as $struc ) {
@ -322,6 +343,9 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
$ret[ $struc['name'] ] = $struc; $ret[ $struc['name'] ] = $struc;
} }
reset_mbstring_encoding();
return $ret; return $ret;
} }