4141use OC \Files \Storage \Home ;
4242use OC \Files \Storage \Wrapper \PermissionsMask ;
4343use OC \User \DisplayNameCache ;
44+ use OC \Files \Storage \Wrapper \Wrapper ;
4445use OC \User \NoUserException ;
4546use OCA \Files_External \Config \ExternalMountPoint ;
4647use OCP \Constants ;
@@ -96,6 +97,8 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
9697
9798 private string $ sourcePath = '' ;
9899
100+ private static int $ initDepth = 0 ;
101+
99102 public function __construct ($ arguments ) {
100103 $ this ->ownerView = $ arguments ['ownerView ' ];
101104 $ this ->logger = \OC ::$ server ->get (LoggerInterface::class);
@@ -135,8 +138,15 @@ private function init() {
135138 if ($ this ->initialized ) {
136139 return ;
137140 }
141+
138142 $ this ->initialized = true ;
143+ self ::$ initDepth ++;
144+
139145 try {
146+ if (self ::$ initDepth > 10 ) {
147+ throw new \Exception ("Maximum share depth reached " );
148+ }
149+
140150 /** @var IRootFolder $rootFolder */
141151 $ rootFolder = \OC ::$ server ->get (IRootFolder::class);
142152 $ this ->ownerUserFolder = $ rootFolder ->getUserFolder ($ this ->superShare ->getShareOwner ());
@@ -149,6 +159,9 @@ private function init() {
149159 $ this ->cache = new FailedCache ();
150160 $ this ->rootPath = '' ;
151161 } else {
162+ if ($ this ->nonMaskedStorage instanceof Wrapper && $ this ->nonMaskedStorage ->isWrapperOf ($ this )) {
163+ throw new \Exception ('recursive share detected ' );
164+ }
152165 $ this ->nonMaskedStorage = $ ownerNode ->getStorage ();
153166 $ this ->sourcePath = $ ownerNode ->getPath ();
154167 $ this ->rootPath = $ ownerNode ->getInternalPath ();
@@ -177,6 +190,7 @@ private function init() {
177190 if (!$ this ->nonMaskedStorage ) {
178191 $ this ->nonMaskedStorage = $ this ->storage ;
179192 }
193+ self ::$ initDepth --;
180194 }
181195
182196 /**
0 commit comments