Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(files): memory usage in filter_wp_read_image_metadata() #5554

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions files/class-api-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,21 @@ public function get_file( $file_path ) {
return $file;
}

// calculate timeout
$info = array();
$this->is_file( $file_path, $info );
if ( is_wp_error( $info ) ) {
return $info;
}

$request_timeout = $this->calculate_upload_timeout( $info['size'] );
$tmp_file = $this->cache->create_tmp_file();

// Request args for wp_remote_request()
$request_args = [
'stream' => true,
'filename' => $tmp_file,
'timeout' => $request_timeout,
];

// not in cache so get from API
Expand Down
3 changes: 1 addition & 2 deletions files/class-vip-filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,7 @@ public function filter_wp_read_image_metadata( $meta, $file ) {

// Save a local copy and read metadata from that
$temp_file = wp_tempnam();
// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_file_put_contents, WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown
file_put_contents( $temp_file, file_get_contents( $file ) );
copy( $file, $temp_file );
$meta = wp_read_image_metadata( $temp_file );

add_filter( 'wp_read_image_metadata', [ $this, 'filter_wp_read_image_metadata' ], 10, 2 );
Expand Down
Loading