Skip to content

Commit b2eb302

Browse files
committed
fix: prevent restoring a file that's larger than the free space
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent ca4ce5a commit b2eb302

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

apps/files_trashbin/lib/Trashbin.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OCP\Files\Folder;
3333
use OCP\Files\IRootFolder;
3434
use OCP\Files\Node;
35+
use OCP\Files\NotEnoughSpaceException;
3536
use OCP\Files\NotFoundException;
3637
use OCP\Files\NotPermittedException;
3738
use OCP\Files\Storage\ILockingStorage;
@@ -554,6 +555,13 @@ public static function restore($file, $filename, $timestamp) {
554555

555556
$sourceNode = self::getNodeForPath($sourcePath);
556557
$targetNode = self::getNodeForPath($targetPath);
558+
559+
$targetParent = $targetNode->getParent();
560+
561+
$free = $targetParent->getFreeSpace();
562+
if ($free >= 0 && $free < $sourceNode->getSize(false)) {
563+
throw new NotEnoughSpaceException('Not enough free space in ' . $targetParent->getPath() . ' to restore ' . $sourceNode->getPath());
564+
}
557565
$run = true;
558566
$event = new BeforeNodeRestoredEvent($sourceNode, $targetNode, $run);
559567
$dispatcher = \OC::$server->get(IEventDispatcher::class);

0 commit comments

Comments
 (0)