Skip to content

Commit 21c75ec

Browse files
author
Viktor Sevch
committed
MC-39340: Improve image upload
1 parent 263f508 commit 21c75ec

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Gallery/UploadTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,19 @@ public function uploadActionWithErrorsDataProvider(): array
210210
'errorcode' => 0,
211211
],
212212
],
213+
'upload_wrong_png' => [
214+
'file' => [
215+
'copy_file' => true,
216+
'name' => 'magento_wrong.png',
217+
'type' => 'image/png',
218+
'current_path' => '/../../../../_files',
219+
],
220+
'expectation' => [
221+
'message' => 'Unsupported image format.',
222+
'errorcode' => 0,
223+
'tmp_media_path' => '/m/w/magento_wrong.png',
224+
],
225+
]
213226
];
214227
}
215228

Loading

lib/internal/Magento/Framework/Image/Adapter/Gd2.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Framework\Image\Adapter;
88

9+
use Magento\Framework\Exception\LocalizedException;
10+
911
/**
1012
* Gd2 adapter.
1113
*
@@ -56,7 +58,7 @@ protected function _reset()
5658
*
5759
* @param string $filename
5860
* @return void
59-
* @throws \OverflowException
61+
* @throws \OverflowException|LocalizedException
6062
*/
6163
public function open($filename)
6264
{
@@ -71,10 +73,11 @@ public function open($filename)
7173
throw new \OverflowException('Memory limit has been reached.');
7274
}
7375
$this->imageDestroy();
74-
$this->_imageHandler = call_user_func(
75-
$this->_getCallback('create', null, sprintf('Unsupported image format. File: %s', $this->_fileName)),
76-
$this->_fileName
77-
);
76+
try {
77+
$this->_imageHandler = call_user_func($this->_getCallback('create'), $this->_fileName);
78+
} catch (\Exception $ex) {
79+
throw new LocalizedException(__('Unsupported image format.'));
80+
}
7881
}
7982

8083
/**

0 commit comments

Comments
 (0)