FIX for #7606: Ensure the object we're handling is actually an Image instance before calling methods specific to that class (e.g. in case of using SVG's in <img> tag which may be File instances).

This commit is contained in:
Patrick Nelson 2017-11-15 19:04:45 -08:00 committed by Daniel Hensby
parent ef86b16854
commit 52f0eadd3b
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E

View File

@ -87,13 +87,14 @@ class HtmlEditorField extends TextareaField {
$img->setAttribute('src', preg_replace('/([^\?]*)\?r=[0-9]+$/i', '$1', $img->getAttribute('src')));
// Resample the images if the width & height have changed.
if($image = File::find(urldecode(Director::makeRelative($img->getAttribute('src'))))){
$image = File::find(urldecode(Director::makeRelative($img->getAttribute('src'))));
if($image instanceof Image){
$width = (int)$img->getAttribute('width');
$height = (int)$img->getAttribute('height');
if($width && $height && ($width != $image->getWidth() || $height != $image->getHeight())) {
//Make sure that the resized image actually returns an image:
$resized=$image->ResizedImage($width, $height);
$resized = $image->ResizedImage($width, $height);
if($resized) $img->setAttribute('src', $resized->getRelativePath());
}
}