summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfox <[email protected]>2021-02-22 23:10:43 +0300
committerfox <[email protected]>2021-02-22 23:10:43 +0300
commitac6cea859a4d4b0c01a35502d62ef7a43fce62c7 (patch)
tree3f32da2bd0c1d76011d82350f239060422db1dd7
parent42173386b39bed4b06c5ac6c2fc0da510673b354 (diff)
parent7c966b69d5b06ea7c1bf418175db782d0e91e92d (diff)
Merge pull request 'Check whether data is parsable by 'imagecreatefromstring' in jimIcon.' (#7) from wn/tt-rss:jimIcon-imagecreatefromstring into master
Reviewed-on: https://git.tt-rss.org/fox/tt-rss/pulls/7
-rw-r--r--lib/jimIcon.php17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/jimIcon.php b/lib/jimIcon.php
index f8e533f90..eaa768272 100644
--- a/lib/jimIcon.php
+++ b/lib/jimIcon.php
@@ -104,11 +104,11 @@ class jimIcon {
}
// See if we can parse it (might be PNG format here)
- $i = @imagecreatefromstring($data);
-
- if ($i) {
- imagesavealpha($i, true);
- return $i;
+ if (self::has_parsable_image_type($data)) {
+ if ($i = @imagecreatefromstring($data)) {
+ imagesavealpha($i, true);
+ return $i;
+ }
}
// Must be a BMP. Parse it ourselves.
@@ -267,5 +267,12 @@ class jimIcon {
}
return $img;
}
+
+ // Checks whether the data is a type parsable by imagecreatefromstring()
+ private function has_parsable_image_type($image_data) {
+ $size = getimagesizefromstring($image_data);
+ return $size && in_array($size[2],
+ [IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_BMP, IMAGETYPE_WBMP, IMAGETYPE_WEBP]);
+ }
}
?>