-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add checks before using size data in image_get_intermediate_size()
#3143
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -774,24 +774,28 @@ function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { | |
| $imagedata['width'] = $imagedata['sizes']['full']['width']; | ||
| } | ||
|
|
||
| foreach ( $imagedata['sizes'] as $_size => $data ) { | ||
| foreach ( $imagedata['sizes'] as $_size => $size_data ) { | ||
| if ( ! is_array( $size_data ) || ! isset( $size_data['width'] ) || ! isset( $size_data['height'] ) ) { | ||
| continue; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silently skipping isn't preferred here. Why?
|
||
| } | ||
|
|
||
| // If there's an exact match to an existing image size, short circuit. | ||
| if ( (int) $data['width'] === (int) $size[0] && (int) $data['height'] === (int) $size[1] ) { | ||
| $candidates[ $data['width'] * $data['height'] ] = $data; | ||
| if ( (int) $size_data['width'] === (int) $size[0] && (int) $size_data['height'] === (int) $size[1] ) { | ||
| $candidates[ $size_data['width'] * $size_data['height'] ] = $size_data; | ||
| break; | ||
| } | ||
|
|
||
| // If it's not an exact match, consider larger sizes with the same aspect ratio. | ||
| if ( $data['width'] >= $size[0] && $data['height'] >= $size[1] ) { | ||
| if ( $size_data['width'] >= $size[0] && $size_data['height'] >= $size[1] ) { | ||
| // If '0' is passed to either size, we test ratios against the original file. | ||
| if ( 0 === $size[0] || 0 === $size[1] ) { | ||
| $same_ratio = wp_image_matches_ratio( $data['width'], $data['height'], $imagedata['width'], $imagedata['height'] ); | ||
| $same_ratio = wp_image_matches_ratio( $size_data['width'], $size_data['height'], $imagedata['width'], $imagedata['height'] ); | ||
| } else { | ||
| $same_ratio = wp_image_matches_ratio( $data['width'], $data['height'], $size[0], $size[1] ); | ||
| $same_ratio = wp_image_matches_ratio( $size_data['width'], $size_data['height'], $size[0], $size[1] ); | ||
| } | ||
|
|
||
| if ( $same_ratio ) { | ||
| $candidates[ $data['width'] * $data['height'] ] = $data; | ||
| $candidates[ $size_data['width'] * $size_data['height'] ] = $size_data; | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_array()isn't needed here as theisset()is checking it.