[wp-trac] [WordPress Trac] #43255: WP_Image_Editor::make_image leaves an output buffer open on failure

WordPress Trac noreply at wordpress.org
Thu Feb 8 02:01:03 UTC 2018


#43255: WP_Image_Editor::make_image leaves an output buffer open on failure
--------------------------+-----------------------------
 Reporter:  gnif          |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  3.5
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 WP_Image_Editor::make_image is failing to clean up on failure leaving an
 output buffer open.

 If the call to fopen fails the function returns without calling
 'ob_end_clean()'


 {{{
   protected function make_image( $filename, $function, $arguments ) {
     if ( $stream = wp_is_stream( $filename ) ) {
       ob_start();
     } else {
       // The directory containing the original file may no longer exist
 when using a replication plugin.
       wp_mkdir_p( dirname( $filename ) );
     }

     $result = call_user_func_array( $function, $arguments );

     if ( $result && $stream ) {
       $contents = ob_get_contents();

       $fp = fopen( $filename, 'w' );

       if ( ! $fp )
       {
         ob_end_clean(); // <-- This is needed
         return false;
       }

       fwrite( $fp, $contents );
       fclose( $fp );
     }

     if ( $stream ) {
       ob_end_clean();
     }

     return $result;
   }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/43255>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list