Skip to content

Bugfix/security exception #3627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static void handleActivityResult(int requestCode, int resultCode, Intent
public static List<UploadableFile> handleExternalImagesPicked(Intent data, Activity activity) {
try {
return getFilesFromGalleryPictures(data, activity);
} catch (IOException e) {
} catch (IOException | SecurityException e) {
e.printStackTrace();
}
return new ArrayList<>();
Expand Down Expand Up @@ -207,7 +207,7 @@ private static void onPictureReturnedFromGallery(Intent data, Activity activity,
}
}

private static List<UploadableFile> getFilesFromGalleryPictures(Intent data, Activity activity) throws IOException {
private static List<UploadableFile> getFilesFromGalleryPictures(Intent data, Activity activity) throws IOException, SecurityException {
List<UploadableFile> files = new ArrayList<>();
ClipData clipData = data.getClipData();
if (clipData == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,15 @@ static void scanCopiedImages(Context context, List<File> copiedImages) {
});
}

static UploadableFile pickedExistingPicture(@NonNull Context context, Uri photoUri) throws IOException {
static UploadableFile pickedExistingPicture(@NonNull Context context, Uri photoUri) throws IOException, SecurityException {// SecurityException for those file providers who share URI but forget to grant necessary permissions
InputStream pictureInputStream = context.getContentResolver().openInputStream(photoUri);
File directory = tempImageDirectory(context);
File photoFile = new File(directory, UUID.randomUUID().toString() + "." + getMimeType(context, photoUri));
photoFile.createNewFile();
writeToFile(pictureInputStream, photoFile);
if (photoFile.createNewFile()) {
writeToFile(pictureInputStream, photoFile);
} else {
throw new IOException("could not create photoFile to write upon");
}
return new UploadableFile(photoUri, photoFile);
}

Expand Down