File tree Expand file tree Collapse file tree
java/com/commonsware/android/cp/files
GrantUriPermissions/app/src/main/java/com/commonsware/android/cp/perms Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,7 +49,13 @@ public boolean onCreate() {
4949 @ Override
5050 public ParcelFileDescriptor openFile (Uri uri , String mode )
5151 throws FileNotFoundException {
52- File f =new File (getContext ().getFilesDir (), uri .getPath ());
52+ File root =getContext ().getFilesDir ();
53+ File f =new File (root , uri .getPath ()).getAbsoluteFile ();
54+
55+ if (!f .getPath ().startsWith (root .getPath ())) {
56+ throw new
57+ SecurityException ("Resolved path jumped beyond root" );
58+ }
5359
5460 if (f .exists ()) {
5561 return (ParcelFileDescriptor .open (f , parseMode (mode )));
Original file line number Diff line number Diff line change @@ -49,7 +49,13 @@ public boolean onCreate() {
4949 @ Override
5050 public ParcelFileDescriptor openFile (Uri uri , String mode )
5151 throws FileNotFoundException {
52- File f =new File (getContext ().getFilesDir (), uri .getPath ());
52+ File root =getContext ().getFilesDir ();
53+ File f =new File (root , uri .getPath ()).getAbsoluteFile ();
54+
55+ if (!f .getPath ().startsWith (root .getPath ())) {
56+ throw new
57+ SecurityException ("Resolved path jumped beyond root" );
58+ }
5359
5460 if (f .exists ()) {
5561 return (ParcelFileDescriptor .open (f , parseMode (mode )));
You can’t perform that action at this time.
0 commit comments