Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/iNPUTmice/Conversations.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2022-08-12 10:58:33 +0300
committerDaniel Gultsch <daniel@gultsch.de>2022-08-12 10:58:35 +0300
commit7cc96e704e5d35637b66d49537d40e7e3c5d03ca (patch)
treed346085fcc59c613c0c89971a4f22a1d42627c1e
parent150f8313a0d97cf71980a380c1d8e8070a23ec81 (diff)
do not retrieve media attributes from encrypted files
fixes #4353
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java2
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java137
2 files changed, 77 insertions, 62 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java b/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java
index a676e5d5d..db84e0cf4 100644
--- a/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java
+++ b/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java
@@ -207,8 +207,8 @@ public class PgpDecryptionService {
}
}
final String url = message.getFileParams().url;
- mXmppConnectionService.getFileBackend().updateFileParams(message, url);
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
+ mXmppConnectionService.getFileBackend().updateFileParams(message, url);
mXmppConnectionService.updateMessage(message);
if (!inputFile.delete()) {
Log.w(Config.LOGTAG,"unable to delete pgp encrypted source file "+inputFile.getAbsolutePath());
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
index c3093f2cf..0d1c03fcb 100644
--- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
@@ -66,7 +66,6 @@ import eu.siacs.conversations.services.AttachFileToConversationRunnable;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.ui.adapter.MediaAdapter;
import eu.siacs.conversations.ui.util.Attachment;
-import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.FileUtils;
import eu.siacs.conversations.utils.FileWriterException;
@@ -400,25 +399,23 @@ public class FileBackend {
public static Uri getMediaUri(Context context, File file) {
final String filePath = file.getAbsolutePath();
- final Cursor cursor;
- try {
- cursor =
- context.getContentResolver()
- .query(
- MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
- new String[] {MediaStore.Images.Media._ID},
- MediaStore.Images.Media.DATA + "=? ",
- new String[] {filePath},
- null);
- } catch (SecurityException e) {
- return null;
- }
- if (cursor != null && cursor.moveToFirst()) {
- final int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
- cursor.close();
- return Uri.withAppendedPath(
- MediaStore.Images.Media.EXTERNAL_CONTENT_URI, String.valueOf(id));
- } else {
+ try (final Cursor cursor =
+ context.getContentResolver()
+ .query(
+ MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
+ new String[] {MediaStore.Images.Media._ID},
+ MediaStore.Images.Media.DATA + "=? ",
+ new String[] {filePath},
+ null)) {
+ if (cursor != null && cursor.moveToFirst()) {
+ final int id =
+ cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns._ID));
+ return Uri.withAppendedPath(
+ MediaStore.Images.Media.EXTERNAL_CONTENT_URI, String.valueOf(id));
+ } else {
+ return null;
+ }
+ } catch (final Exception e) {
return null;
}
}
@@ -1492,57 +1489,73 @@ public class FileBackend {
updateFileParams(message, null);
}
- public void updateFileParams(Message message, String url) {
- DownloadableFile file = getFile(message);
+ public void updateFileParams(final Message message, final String url) {
+ final boolean encrypted =
+ message.getEncryption() == Message.ENCRYPTION_PGP
+ || message.getEncryption() == Message.ENCRYPTION_DECRYPTED;
+ final DownloadableFile file = getFile(message);
final String mime = file.getMimeType();
- final boolean privateMessage = message.isPrivateMessage();
- final boolean ambiguous = MimeUtils.AMBIGUOUS_CONTAINER_FORMATS.contains(mime);
final boolean image =
message.getType() == Message.TYPE_IMAGE
|| (mime != null && mime.startsWith("image/"));
- final boolean video = mime != null && mime.startsWith("video/");
- final boolean audio = mime != null && mime.startsWith("audio/");
- final boolean pdf = "application/pdf".equals(mime);
+ final boolean privateMessage = message.isPrivateMessage();
final StringBuilder body = new StringBuilder();
if (url != null) {
body.append(url);
}
- body.append('|').append(file.getSize());
- if (ambiguous) {
- try {
- final Dimensions dimensions = getVideoDimensions(file);
- if (dimensions.valid()) {
- Log.d(Config.LOGTAG,"ambiguous file "+mime+" is video");
- body.append('|').append(dimensions.width).append('|').append(dimensions.height);
- } else {
- Log.d(Config.LOGTAG,"ambiguous file "+mime+" is audio");
+ if (encrypted && !file.exists()) {
+ Log.d(Config.LOGTAG, "skipping updateFileParams because file is encrypted");
+ final DownloadableFile encryptedFile = getFile(message, false);
+ body.append('|').append(encryptedFile.getSize());
+ } else {
+ Log.d(Config.LOGTAG, "running updateFileParams");
+ final boolean ambiguous = MimeUtils.AMBIGUOUS_CONTAINER_FORMATS.contains(mime);
+ final boolean video = mime != null && mime.startsWith("video/");
+ final boolean audio = mime != null && mime.startsWith("audio/");
+ final boolean pdf = "application/pdf".equals(mime);
+ body.append('|').append(file.getSize());
+ if (ambiguous) {
+ try {
+ final Dimensions dimensions = getVideoDimensions(file);
+ if (dimensions.valid()) {
+ Log.d(Config.LOGTAG, "ambiguous file " + mime + " is video");
+ body.append('|')
+ .append(dimensions.width)
+ .append('|')
+ .append(dimensions.height);
+ } else {
+ Log.d(Config.LOGTAG, "ambiguous file " + mime + " is audio");
+ body.append("|0|0|").append(getMediaRuntime(file));
+ }
+ } catch (final NotAVideoFile e) {
+ Log.d(Config.LOGTAG, "ambiguous file " + mime + " is audio");
body.append("|0|0|").append(getMediaRuntime(file));
}
- } catch (final NotAVideoFile e) {
- Log.d(Config.LOGTAG,"ambiguous file "+mime+" is audio");
- body.append("|0|0|").append(getMediaRuntime(file));
- }
- } else if (image || video || pdf) {
- try {
- final Dimensions dimensions;
- if (video) {
- dimensions = getVideoDimensions(file);
- } else if (pdf) {
- dimensions = getPdfDocumentDimensions(file);
- } else {
- dimensions = getImageDimensions(file);
- }
- if (dimensions.valid()) {
- body.append('|').append(dimensions.width).append('|').append(dimensions.height);
+ } else if (image || video || pdf) {
+ try {
+ final Dimensions dimensions;
+ if (video) {
+ dimensions = getVideoDimensions(file);
+ } else if (pdf) {
+ dimensions = getPdfDocumentDimensions(file);
+ } else {
+ dimensions = getImageDimensions(file);
+ }
+ if (dimensions.valid()) {
+ body.append('|')
+ .append(dimensions.width)
+ .append('|')
+ .append(dimensions.height);
+ }
+ } catch (NotAVideoFile notAVideoFile) {
+ Log.d(
+ Config.LOGTAG,
+ "file with mime type " + file.getMimeType() + " was not a video file");
+ // fall threw
}
- } catch (NotAVideoFile notAVideoFile) {
- Log.d(
- Config.LOGTAG,
- "file with mime type " + file.getMimeType() + " was not a video file");
- // fall threw
+ } else if (audio) {
+ body.append("|0|0|").append(getMediaRuntime(file));
}
- } else if (audio) {
- body.append("|0|0|").append(getMediaRuntime(file));
}
message.setBody(body.toString());
message.setDeleted(false);
@@ -1556,12 +1569,14 @@ public class FileBackend {
try {
final MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(file.toString());
- final String value = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
+ final String value =
+ mediaMetadataRetriever.extractMetadata(
+ MediaMetadataRetriever.METADATA_KEY_DURATION);
if (Strings.isNullOrEmpty(value)) {
return 0;
}
return Integer.parseInt(value);
- } catch (NumberFormatException e) {
+ } catch (final IllegalArgumentException e) {
return 0;
}
}