Ticket #23127: 23127.patch
File 23127.patch, 4.4 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-image-editor-gd.php
78 78 } 79 79 80 80 /** 81 * Catches fatal PHP errors that aren't normally relayed to the user 82 */ 83 public function catch_fatal_errors() { 84 header('Status: 500 Internal Server Error'); 85 $error = error_get_last(); 86 echo $error['message']; 87 } 88 89 /** 81 90 * Loads image from $this->file into new GD Resource. 82 91 * 83 92 * @since 3.5.0 … … 93 102 94 103 // Set artificially high because GD uses uncompressed images in memory. 95 104 wp_raise_memory_limit( 'image' ); 96 97 $this->image = @imagecreatefromstring( file_get_contents( $this->file ) ); 98 105 106 add_action( 'shutdown', array( $this,'catch_fatal_errors' ) ); 107 108 $size = getimagesize( $this->file ); 109 110 if ( ! $size ) 111 return new WP_Error( 'invalid_image', __('Could not read image size.'), $this->file ); 112 113 // See if image dimensions will exhaust memory and avoid a fatal error 114 // https://core.trac.wordpress.org/ticket/23127#comment:1 115 $mem_usage = memory_get_usage(); 116 $mem_limit = ini_get('memory_limit'); 117 switch ( substr($mem_limit, -1) ) { 118 case 'G': case 'g': $mem_limit = (int) $mem_limit * 1073741824;break; 119 case 'M': case 'm': $mem_limit = (int) $mem_limit * 1048576; break; 120 case 'K': case 'k': $mem_limit = (int) $mem_limit * 1024; break; 121 default: $mem_limit = (int) $mem_limit; 122 } 123 $est_mem_usage = $size[0] * $size[1] * $size['bits'] * $size['channels'] / 8 * 1.65; 124 if ( ( $mem_limit - $mem_usage ) < $est_mem_usage ) 125 return new WP_Error( 'image_memory_exceeded', __('Memory estimated to be exceeded. Please try another smaller file.'), $this->file ); 126 127 $this->image = imagecreatefromstring( file_get_contents( $this->file ) ); 128 99 129 if ( ! is_resource( $this->image ) ) 100 130 return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file ); 101 131 102 $size = @getimagesize( $this->file );103 if ( ! $size )104 return new WP_Error( 'invalid_image', __('Could not read image size.'), $this->file );105 106 132 if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) { 107 133 imagealphablending( $this->image, false ); 108 134 imagesavealpha( $this->image, true ); … … 110 136 111 137 $this->update_size( $size[0], $size[1] ); 112 138 $this->mime_type = $size['mime']; 113 139 140 remove_action( 'shutdown', array( $this,'catch_fatal_errors' ) ); 141 114 142 return $this->set_quality(); 115 143 } 116 144 -
src/wp-admin/includes/image.php
131 131 if ( $sizes ) { 132 132 $editor = wp_get_image_editor( $file ); 133 133 134 if ( ! is_wp_error( $editor ) ) 134 if ( ! is_wp_error( $editor ) ) { 135 135 $metadata['sizes'] = $editor->multi_resize( $sizes ); 136 } else { 137 $metadata['sizes'] = array(); 138 } 136 139 } else { 137 140 $metadata['sizes'] = array(); 138 141 } -
src/wp-includes/js/plupload/plupload.js
1380 1380 } else { 1381 1381 file.loaded = offset; // reset all progress 1382 1382 1383 up.trigger('Error', { 1384 code : plupload.HTTP_ERROR, 1385 message : plupload.translate('HTTP Error.'), 1386 file : file, 1387 response : xhr.responseText, 1388 status : xhr.status, 1389 responseHeaders: xhr.getAllResponseHeaders() 1390 }); 1383 if ( xhr.responseText && xhr.responseText.indexOf('memory') > 0 && xhr.responseText.indexOf('exhausted') > 0 ) { 1384 up.trigger('Error', { 1385 code : plupload.IMAGE_MEMORY_ERROR, 1386 message : plupload.translate('Memory exceeded. Please try another smaller file.'), 1387 file : file, 1388 response : xhr.responseText, 1389 status : xhr.status, 1390 responseHeaders: xhr.getAllResponseHeaders() 1391 }); 1392 } else { 1393 up.trigger('Error', { 1394 code : plupload.HTTP_ERROR, 1395 message : plupload.translate('HTTP Error.'), 1396 file : file, 1397 response : xhr.responseText, 1398 status : xhr.status, 1399 responseHeaders: xhr.getAllResponseHeaders() 1400 }); 1401 } 1391 1402 } 1392 1403 } 1393 1404