Skip to content

Commit 6c1b09d

Browse files
author
Dmytro Voskoboinikov
committed
Merge branch 'MAGETWO-92164' into 2.1.15-bugfixes-210618
2 parents ab1c778 + dd70606 commit 6c1b09d

File tree

6 files changed

+29
-604
lines changed

6 files changed

+29
-604
lines changed

app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Framework\App\Filesystem\DirectoryList;
1111
use Magento\Catalog\Model\Product\Exception as ProductException;
1212
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Framework\Math\Random;
14+
use Magento\Framework\App\ObjectManager;
1315

1416
/**
1517
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -62,25 +64,34 @@ class ValidatorFile extends Validator
6264
*/
6365
protected $isImageValidator;
6466

67+
/**
68+
* @var Random
69+
*/
70+
private $random;
71+
6572
/**
6673
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
6774
* @param \Magento\Framework\Filesystem $filesystem
6875
* @param \Magento\Framework\File\Size $fileSize
6976
* @param \Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory
7077
* @param \Magento\Framework\Validator\File\IsImage $isImageValidator
78+
* @param Random|null $random
7179
* @throws \Magento\Framework\Exception\FileSystemException
7280
*/
7381
public function __construct(
7482
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
7583
\Magento\Framework\Filesystem $filesystem,
7684
\Magento\Framework\File\Size $fileSize,
7785
\Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory,
78-
\Magento\Framework\Validator\File\IsImage $isImageValidator
86+
\Magento\Framework\Validator\File\IsImage $isImageValidator,
87+
Random $random = null
7988
) {
8089
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
8190
$this->filesystem = $filesystem;
8291
$this->httpFactory = $httpFactory;
8392
$this->isImageValidator = $isImageValidator;
93+
$this->random = $random
94+
? $random : ObjectManager::getInstance()->get(Random::class);
8495
parent::__construct($scopeConfig, $filesystem, $fileSize);
8596
}
8697

@@ -147,16 +158,14 @@ public function validate($processingParams, $option)
147158
$userValue = [];
148159

149160
if ($upload->isUploaded($file) && $upload->isValid($file)) {
150-
$extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION);
151-
152161
$fileName = \Magento\MediaStorage\Model\File\Uploader::getCorrectFileName($fileInfo['name']);
153162
$dispersion = \Magento\MediaStorage\Model\File\Uploader::getDispretionPath($fileName);
154163

155164
$filePath = $dispersion;
156165

157166
$tmpDirectory = $this->filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
158-
$fileHash = md5($tmpDirectory->readFile($tmpDirectory->getRelativePath($fileInfo['tmp_name'])));
159-
$filePath .= '/' . $fileHash . '.' . $extension;
167+
$fileHash = $this->random->getRandomString(32);
168+
$filePath .= '/' . $fileHash;
160169
$fileFullPath = $this->mediaDirectory->getAbsolutePath($this->quotePath . $filePath);
161170

162171
$upload->addFilter(new \Zend_Filter_File_Rename(['target' => $fileFullPath, 'overwrite' => true]));

app/code/Magento/Sales/Model/Download.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public function downloadFile($info)
7878
$this->_fileFactory->create(
7979
$info['title'],
8080
['value' => $this->_rootDir->getRelativePath($relativePath), 'type' => 'filename'],
81-
$this->rootDirBasePath
81+
$this->rootDirBasePath,
82+
$info['type']
8283
);
8384
}
8485

0 commit comments

Comments
 (0)