Skip to content

Commit c52172c

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-88645' into 2.3-develop-pr26
2 parents 755f33b + 6feedba commit c52172c

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

app/code/Magento/Catalog/Model/Product/Gallery/UpdateHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ protected function processDeletedImages($product, array &$images)
3232
foreach ($images as &$image) {
3333
if (!empty($image['removed'])) {
3434
if (!empty($image['value_id']) && !isset($picturesInOtherStores[$image['file']])) {
35+
if (preg_match('/\.\.(\\\|\/)/', $image['file'])) {
36+
continue;
37+
}
3538
$recordsToDelete[] = $image['value_id'];
3639
$catalogPath = $this->mediaConfig->getBaseMediaPath();
3740
$isFile = $this->mediaDirectory->isFile($catalogPath . $image['file']);
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Model\Product\Gallery;
10+
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Framework\Filesystem;
13+
use Magento\Framework\App\Filesystem\DirectoryList;
14+
use Magento\Framework\ObjectManagerInterface;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use Magento\Framework\Filesystem\Directory\WriteInterface;
17+
18+
/**
19+
* Test for \Magento\Catalog\Model\Product\Gallery\UpdateHandler.
20+
*
21+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
22+
* @magentoDataFixture Magento/Catalog/_files/product_image.php
23+
*/
24+
class UpdateHandlerTest extends \PHPUnit\Framework\TestCase
25+
{
26+
/**
27+
* @var ObjectManagerInterface
28+
*/
29+
private $objectManager;
30+
31+
/**
32+
* @var UpdateHandler
33+
*/
34+
private $updateHandler;
35+
36+
/**
37+
* @var WriteInterface
38+
*/
39+
private $mediaDirectory;
40+
41+
/**
42+
* @var Filesystem
43+
*/
44+
private $filesystem;
45+
46+
/**
47+
* @var string
48+
*/
49+
private $fileName;
50+
51+
/**
52+
* @inheritdoc
53+
*/
54+
protected function setUp()
55+
{
56+
$this->fileName = 'image.txt';
57+
58+
$this->objectManager = Bootstrap::getObjectManager();
59+
$this->updateHandler = $this->objectManager->create(UpdateHandler::class);
60+
$this->filesystem = $this->objectManager->get(Filesystem::class);
61+
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
62+
$this->mediaDirectory->writeFile($this->fileName, 'Test');
63+
}
64+
65+
/**
66+
* @return void
67+
*/
68+
public function testExecuteWithIllegalFilename(): void
69+
{
70+
$filePath = str_repeat('/..', 2) . DIRECTORY_SEPARATOR . $this->fileName;
71+
72+
/** @var $product Product */
73+
$product = Bootstrap::getObjectManager()->create(Product::class);
74+
$product->load(1);
75+
$product->setData(
76+
'media_gallery',
77+
[
78+
'images' => [
79+
'image' => [
80+
'value_id' => '100',
81+
'file' => $filePath,
82+
'label' => 'New image',
83+
'removed' => 1,
84+
],
85+
],
86+
]
87+
);
88+
89+
$this->updateHandler->execute($product);
90+
$this->assertFileExists($this->mediaDirectory->getAbsolutePath($this->fileName));
91+
}
92+
93+
/**
94+
* @return void
95+
*/
96+
protected function tearDown(): void
97+
{
98+
$this->mediaDirectory->getDriver()->deleteFile($this->mediaDirectory->getAbsolutePath($this->fileName));
99+
}
100+
}

0 commit comments

Comments
 (0)