Rethrow SecurityExceptions when opening images.

This commit is contained in:
akwizgran
2022-04-17 11:51:49 +01:00
parent 74a3f54d28
commit c1fabcd46b
2 changed files with 19 additions and 10 deletions

View File

@@ -26,6 +26,7 @@ import static org.briarproject.bramble.util.IoUtils.tryToClose;
import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.LogUtils.now;
import static org.briarproject.briar.android.attachment.media.ImageCompressor.MIME_TYPE;
@NotNullByDefault
class AttachmentCreationTask {
@@ -100,14 +101,17 @@ class AttachmentCreationTask {
if (!asList(getSupportedImageContentTypes()).contains(contentType)) {
throw new UnsupportedMimeTypeException(contentType, uri);
}
InputStream is = contentResolver.openInputStream(uri);
if (is == null) throw new IOException();
is = imageCompressor
.compressImage(is, contentType);
InputStream is;
try {
is = contentResolver.openInputStream(uri);
if (is == null) throw new IOException();
} catch (SecurityException e) {
throw new IOException(e);
}
is = imageCompressor.compressImage(is, contentType);
long timestamp = System.currentTimeMillis();
AttachmentHeader h = messagingManager
.addLocalAttachment(groupId, timestamp,
ImageCompressor.MIME_TYPE, is);
AttachmentHeader h = messagingManager.addLocalAttachment(groupId,
timestamp, MIME_TYPE, is);
tryToClose(is, LOG, WARNING);
logDuration(LOG, "Storing attachment", start);
return h;

View File

@@ -231,9 +231,14 @@ class SettingsViewModel extends DbViewModel implements EventListener {
if (!asList(getSupportedImageContentTypes()).contains(contentType)) {
throw new UnsupportedMimeTypeException(contentType, uri);
}
InputStream is = contentResolver.openInputStream(uri);
if (is == null) throw new IOException(
"ContentResolver returned null when opening InputStream");
InputStream is;
try {
is = contentResolver.openInputStream(uri);
if (is == null) throw new IOException(
"ContentResolver returned null when opening InputStream");
} catch (SecurityException e) {
throw new IOException(e);
}
InputStream compressed = imageCompressor.compressImage(is, contentType);
runOnDbThread(() -> {