Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b2c1689b authored by Tommy Webb's avatar Tommy Webb
Browse files

fixup! SaveImage: Check and strip userID from URI before accessing

Use encodedAuthority instead of authority to match behavior in other
areas of AOSP and prevent potential URI-related shenanigans.

Change-Id: Ia9ce58130ca080a9912a21e94dbfa81fcca94399
parent 4af0462d
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -935,7 +935,7 @@ public class SaveImage {
    }

    private static UserHandle getUserHandleFromUri(Uri uri) {
        if (uri == null || uri.getAuthority() == null) return null;
        if (uri == null || uri.getEncodedAuthority() == null) return null;
        final String userIdString = uri.getUserInfo();
        try {
            return UserHandle.getUserHandleForUid(Integer.parseInt(userIdString) * PER_UID_RANGE);
@@ -946,10 +946,10 @@ public class SaveImage {
    }

    private static Uri getUriWithoutUserId(Uri uri) {
        if (uri == null || uri.getAuthority() == null) return null;
        int end = uri.getAuthority().lastIndexOf('@');
        if (uri == null || uri.getEncodedAuthority() == null) return null;
        int end = uri.getEncodedAuthority().lastIndexOf('@');
        Uri.Builder builder = uri.buildUpon();
        builder.authority(uri.getAuthority().substring(end+1));
        builder.encodedAuthority(uri.getEncodedAuthority().substring(end+1));
        return builder.build();
    }