Make WordPress Core

Ticket #16057: 16057.4.diff

File 16057.4.diff, 2.5 KB (added by wonderboymusic, 11 years ago)
  • wp-includes/class-http.php

    diff --git wp-includes/class-http.php wp-includes/class-http.php
    index 12e73bb..5b5c2b8 100644
    class WP_Http { 
    631631                                $args['method'] = 'GET';
    632632                }
    633633
    634                 return wp_remote_request( $redirect_location, $args ); 
     634                return wp_remote_request( $redirect_location, $args );
    635635        }
    636636}
    637637
    class WP_Http_Fsockopen { 
    852852
    853853                $arrHeaders = WP_Http::processHeaders( $process['headers'] );
    854854
     855                //Check the file was fully written to disk
     856                if ( $r['stream'] && isset( $arrHeaders['headers']['content-length'] ) && (int)$arrHeaders['headers']['content-length'] > $bytes_written ) {
     857                        unlink( $r['filename'] );
     858                        return new WP_Error( 'http_request_failed', __( 'Failed to write full file to disk.' ) );
     859                }
     860
    855861                $response = array(
    856862                        'headers' => $arrHeaders['headers'],
    857863                        'body' => null, // Not yet processed
    class WP_Http_Streams { 
    10301036                        if ( ! $stream_handle )
    10311037                                return new WP_Error( 'http_request_failed', sprintf( __( 'Could not open handle for fopen() to %s' ), $r['filename'] ) );
    10321038
    1033                         stream_copy_to_stream( $handle, $stream_handle, $max_bytes );
     1039                        $bytes_written = stream_copy_to_stream( $handle, $stream_handle, $max_bytes );
    10341040
    10351041                        fclose( $stream_handle );
    10361042                        $strResponse = '';
    class WP_Http_Streams { 
    10481054                else
    10491055                        $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']);
    10501056
     1057                // Check the file was fully written to disk
     1058                if ( $r['stream'] && isset( $processedHeaders['headers']['content-length'] ) ) {
     1059                        if ( (int)$processedHeaders['headers']['content-length'] > $bytes_written && ! ( $bytes_written === 1 && 0 === (int) $processedHeaders['headers']['content-length'] ) ) { // PHP Bug: http://bugs.php.net/bug.php?id=47997 fixed in 5.2.10
     1060                                unlink( $r['filename'] );
     1061                                return new WP_Error( 'http_request_failed', __( 'Failed to write full file to disk.' ) );
     1062                        }
     1063                }
     1064
    10511065                $response = array(
    10521066                        'headers' => $processedHeaders['headers'],
    10531067                        'body' => null,
    class WP_Http_Curl { 
    13181332
    13191333                curl_close( $handle );
    13201334
    1321                 if ( $r['stream'] )
     1335                if ( $r['stream'] ) {
    13221336                        fclose( $this->stream_handle );
     1337                        // Check the file was fully written to disk
     1338                        if ( isset( $theHeaders['headers']['content-length'] ) && (int) $theHeaders['headers']['content-length'] > filesize( $r['filename'] ) ) {
     1339                                unlink( $r['filename'] );
     1340                                return new WP_Error( 'http_request_failed', __( 'Failed to write full file to disk.' ) );
     1341                        }
     1342                }
    13231343
    13241344                $response = array(
    13251345                        'headers' => $theHeaders['headers'],