From 26ebfca466659b3748fbadad1f33842775c21aaf Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 11 Sep 2013 08:27:10 +0000 Subject: [PATCH] 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 --- .../includes/class-wp-filesystem-direct.php | 8 +++++- .../includes/class-wp-filesystem-ftpext.php | 8 +++++- .../class-wp-filesystem-ftpsockets.php | 26 ++++++++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/wp-admin/includes/class-wp-filesystem-direct.php b/wp-admin/includes/class-wp-filesystem-direct.php index 3f5bc64755..f0b6d624a3 100644 --- a/wp-admin/includes/class-wp-filesystem-direct.php +++ b/wp-admin/includes/class-wp-filesystem-direct.php @@ -68,11 +68,17 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { if ( ! $fp ) return false; + mbstring_binary_safe_encoding(); + + $data_length = strlen( $contents ); + $bytes_written = fwrite( $fp, $contents ); + reset_mbstring_encoding(); + fclose( $fp ); - if ( false === $bytes_written || $bytes_written != strlen( $contents ) ) + if ( $data_length !== $bytes_written ) return false; $this->chmod( $file, $mode ); diff --git a/wp-admin/includes/class-wp-filesystem-ftpext.php b/wp-admin/includes/class-wp-filesystem-ftpext.php index f1c3b78097..288b69ad3d 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -118,8 +118,14 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { if ( ! $temp ) return false; + mbstring_binary_safe_encoding(); + + $data_length = strlen( $contents ); $bytes_written = fwrite( $temp, $contents ); - if ( false === $bytes_written || $bytes_written != strlen( $contents ) ) { + + reset_mbstring_encoding(); + + if ( $data_length !== $bytes_written ) { fclose( $temp ); unlink( $tempfile ); return false; diff --git a/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/wp-admin/includes/class-wp-filesystem-ftpsockets.php index f938e85265..eee7920dda 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -89,12 +89,19 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { if ( ! $temphandle = fopen($temp, 'w+') ) return false; + mbstring_binary_safe_encoding(); + if ( ! $this->ftp->fget($temphandle, $file) ) { fclose($temphandle); unlink($temp); + + reset_mbstring_encoding(); + 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 $contents = ''; @@ -117,10 +124,16 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { return false; } + // The FTP class uses string functions internally during file download/upload + mbstring_binary_safe_encoding(); + $bytes_written = fwrite( $temphandle, $contents ); if ( false === $bytes_written || $bytes_written != strlen( $contents ) ) { fclose( $temphandle ); unlink( $temp ); + + reset_mbstring_encoding(); + return false; } @@ -128,6 +141,8 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { $ret = $this->ftp->fput($file, $temphandle); + reset_mbstring_encoding(); + fclose($temphandle); unlink($temp); @@ -293,9 +308,15 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { $limit_file = false; } + mbstring_binary_safe_encoding(); + $list = $this->ftp->dirlist($path); - if ( empty($list) && !$this->exists($path) ) + if ( empty( $list ) && ! $this->exists( $path ) ) { + + reset_mbstring_encoding(); + return false; + } $ret = array(); foreach ( $list as $struc ) { @@ -322,6 +343,9 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { $ret[ $struc['name'] ] = $struc; } + + reset_mbstring_encoding(); + return $ret; }