mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Merge branch '2143-rethrow-security-exceptions-when-opening-images' into 'master'
Rethrow SecurityExceptions when opening images Closes #2143 See merge request briar/briar!1626
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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(() -> {
|
||||
|
||||
Reference in New Issue
Block a user