File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3939import android .view .WindowManager ;
4040
4141import java .io .File ;
42+ import java .io .IOException ;
4243import java .util .HashMap ;
4344import java .util .Locale ;
4445
@@ -300,8 +301,27 @@ private boolean isStorageSubDirectory(String path) {
300301 return false ;
301302 }
302303
304+ // returns true if the path is in the storage root
305+ private boolean inStorageRoot (String path ) {
306+ try {
307+ File f = new File (path );
308+ String canonical = f .getCanonicalPath ();
309+ if (canonical .startsWith (mMediaStoragePath )) {
310+ return true ;
311+ }
312+ } catch (IOException e ) {
313+ // ignore
314+ }
315+ return false ;
316+ }
317+
303318 private int beginSendObject (String path , int format , int parent ,
304319 int storageId , long size , long modified ) {
320+ // if the path is outside of the storage root, do not allow access
321+ if (!inStorageRoot (path )) {
322+ Log .e (TAG , "attempt to put file outside of storage area: " + path );
323+ return -1 ;
324+ }
305325 // if mSubDirectories is not null, do not allow copying files to any other locations
306326 if (!inStorageSubDirectory (path )) return -1 ;
307327
You can’t perform that action at this time.
0 commit comments