Skip to content

Commit 4c6fcba

Browse files
committed
Use single stream to validate custom dashboard image
Signed-off-by: Christopher Ng <[email protected]> (cherry picked from commit f35ff80)
1 parent bb7b115 commit 4c6fcba

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

apps/dashboard/lib/Service/BackgroundService.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
use OCP\IConfig;
3939
use OCP\Lock\LockedException;
4040
use OCP\PreConditionNotMetException;
41+
use Safe\Exceptions\FilesystemException;
42+
use function Safe\rewind;
4143

4244
class BackgroundService {
4345
public const THEMING_MODE_DARK = 'dark';
@@ -143,17 +145,20 @@ public function setDefaultBackground(): void {
143145
* @throws LockedException
144146
* @throws PreConditionNotMetException
145147
* @throws NoUserException
148+
* @throws FilesystemException
146149
*/
147150
public function setFileBackground($path): void {
148151
$this->config->setUserValue($this->userId, 'dashboard', 'background', 'custom');
149152
$userFolder = $this->rootFolder->getUserFolder($this->userId);
150153
/** @var File $file */
151154
$file = $userFolder->get($path);
152155
$image = new \OCP\Image();
153-
if ($image->loadFromFileHandle($file->fopen('r')) === false) {
156+
$stream = $file->fopen('r');
157+
if ($image->loadFromFileHandle($stream) === false) {
154158
throw new InvalidArgumentException('Invalid image file');
155159
}
156-
$this->getAppDataFolder()->newFile('background.jpg', $file->fopen('r'));
160+
rewind($stream);
161+
$this->getAppDataFolder()->newFile('background.jpg', $stream);
157162
}
158163

159164
public function setShippedBackground($fileName): void {

0 commit comments

Comments
 (0)