@@ -39,6 +39,8 @@ class ImageResize
3939
4040 protected $ source_w ;
4141 protected $ source_h ;
42+
43+ protected $ source_info ;
4244
4345 /**
4446 * Create instance from a strng
@@ -49,6 +51,9 @@ class ImageResize
4951 */
5052 public static function createFromString ($ image_data )
5153 {
54+ if (empty ($ image_data ) || $ image_data === null ) {
55+ throw new ImageResizeException ('image_data must not be empty ' );
56+ }
5257 $ resize = new self ('data://application/octet-stream;base64, ' . base64_encode ($ image_data ));
5358 return $ resize ;
5459 }
@@ -62,7 +67,17 @@ public static function createFromString($image_data)
6267 */
6368 public function __construct ($ filename )
6469 {
65- $ image_info = @getimagesize ($ filename );
70+
71+ if ($ filename === null || empty ($ filename ) || (substr ($ filename ,0 ,7 ) !== 'data:// ' && !is_file ($ filename ))) {
72+ throw new ImageResizeException ('File does not exist ' );
73+ }
74+
75+ $ finfo = finfo_open (FILEINFO_MIME_TYPE );
76+ if (strstr (finfo_file ($ finfo , $ filename ),'image ' ) === false ) {
77+ throw new ImageResizeException ('Unsupported file type ' );
78+ }
79+
80+ $ image_info = getimagesize ($ filename ,$ this ->source_info );
6681
6782 if (!$ image_info ) {
6883 throw new ImageResizeException ('Could not read file ' );
@@ -107,12 +122,12 @@ public function __construct($filename)
107122 // http://stackoverflow.com/a/28819866
108123 public function imageCreateJpegfromExif ($ filename ){
109124 $ img = imagecreatefromjpeg ($ filename );
110-
111- if (!function_exists ('exif_read_data ' )) {
125+
126+ if (!function_exists ('exif_read_data ' ) || ! isset ( $ this -> source_info [ ' APP1 ' ]) || strpos ( $ this -> source_info [ ' APP1 ' ], ' Exif ' ) !== 0 ) {
112127 return $ img ;
113128 }
114-
115- $ exif = @ exif_read_data ($ filename );
129+
130+ $ exif = exif_read_data ($ filename );
116131
117132 if (!$ exif || !isset ($ exif ['Orientation ' ])){
118133 return $ img ;
0 commit comments