Skip to content

Commit f11e16f

Browse files
Merge pull request #62462 from nextcloud/backport/60975/stable33
[stable33] fix: harden object store against copying a file to itself
2 parents 3aef83b + a2d0f5d commit f11e16f

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,11 @@ private function copyInner(ICache $sourceCache, ICacheEntry $sourceEntry, string
708708
$this->copyInner($sourceCache, $child, $to . '/' . $child->getName());
709709
}
710710
} else {
711-
$this->copyFile($sourceEntry, $to);
711+
$this->copyFile($sourceCache, $sourceEntry, $to);
712712
}
713713
}
714714

715-
private function copyFile(ICacheEntry $sourceEntry, string $to) {
715+
private function copyFile(ICache $sourceCache, ICacheEntry $sourceEntry, string $to) {
716716
$cache = $this->getCache();
717717

718718
$sourceUrn = $this->getURN($sourceEntry->getId());
@@ -721,7 +721,19 @@ private function copyFile(ICacheEntry $sourceEntry, string $to) {
721721
throw new \Exception('Invalid source cache for object store copy');
722722
}
723723

724-
$targetId = $cache->copyFromCache($cache, $sourceEntry, $to);
724+
$targetId = $cache->copyFromCache($sourceCache, $sourceEntry, $to);
725+
726+
if ($targetId === $sourceEntry->getId()) {
727+
// copying a file to itself? No need to do anything
728+
$e = new \Exception('Object ' . $sourceEntry->getPath() . ' (' . $sourceEntry->getId() . ') being copied to itself');
729+
if ($sourceEntry instanceof CacheEntry) {
730+
$sourceData = $sourceEntry->getData();
731+
} else {
732+
$sourceData = null;
733+
}
734+
$this->logger->warning($e->getMessage(), ['exception' => $e, 'source' => $sourceData]);
735+
return;
736+
}
725737

726738
$targetUrn = $this->getURN($targetId);
727739

0 commit comments

Comments
 (0)