4141use OC \Files \Storage \FailedStorage ;
4242use OC \Files \Storage \Home ;
4343use OC \Files \Storage \Wrapper \PermissionsMask ;
44+ use OC \Files \Storage \Wrapper \Wrapper ;
4445use OC \User \NoUserException ;
4546use OCA \Files_External \Config \ConfigAdapter ;
4647use OCP \Constants ;
@@ -97,6 +98,8 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
9798
9899 private string $ sourcePath = '' ;
99100
101+ static private int $ initDepth = 0 ;
102+
100103 public function __construct ($ arguments ) {
101104 $ this ->ownerView = $ arguments ['ownerView ' ];
102105 $ this ->logger = \OC ::$ server ->get (LoggerInterface::class);
@@ -136,8 +139,15 @@ private function init() {
136139 if ($ this ->initialized ) {
137140 return ;
138141 }
142+
139143 $ this ->initialized = true ;
144+ self ::$ initDepth ++;
145+
140146 try {
147+ if (self ::$ initDepth > 10 ) {
148+ throw new \Exception ("Maximum share depth reached " );
149+ }
150+
141151 /** @var IRootFolder $rootFolder */
142152 $ rootFolder = \OC ::$ server ->get (IRootFolder::class);
143153 $ this ->ownerUserFolder = $ rootFolder ->getUserFolder ($ this ->superShare ->getShareOwner ());
@@ -150,6 +160,9 @@ private function init() {
150160 $ this ->cache = new FailedCache ();
151161 $ this ->rootPath = '' ;
152162 } else {
163+ if ($ this ->nonMaskedStorage instanceof Wrapper && $ this ->nonMaskedStorage ->isWrapperOf ($ this )) {
164+ throw new \Exception ('recursive share detected ' );
165+ }
153166 $ this ->nonMaskedStorage = $ ownerNode ->getStorage ();
154167 $ this ->sourcePath = $ ownerNode ->getPath ();
155168 $ this ->rootPath = $ ownerNode ->getInternalPath ();
@@ -178,6 +191,7 @@ private function init() {
178191 if (!$ this ->nonMaskedStorage ) {
179192 $ this ->nonMaskedStorage = $ this ->storage ;
180193 }
194+ self ::$ initDepth --;
181195 }
182196
183197 /**
@@ -411,7 +425,7 @@ public function getCache($path = '', $storage = null) {
411425 return new FailedCache ();
412426 }
413427
414- $ this ->cache = new Cache (
428+ $ this ->cache = new \ OCA \ Files_Sharing \ Cache (
415429 $ storage ,
416430 $ sourceRoot ,
417431 \OC ::$ server ->get (CacheDependencies::class),
0 commit comments