From a6a1f89124c09d325a4570025df974b35158ebda Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 3 May 2018 21:52:29 +0200 Subject: handle invalid image bounds --- src/main/java/de/pixart/messenger/persistance/FileBackend.java | 8 +++++++- src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java | 4 +--- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index c4107e863..7ba41d8ad 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -912,7 +912,9 @@ public class FileBackend { if (image || video) { try { Dimensions dimensions = image ? getImageDimensions(file) : getVideoDimensions(file); - body.append('|').append(dimensions.width).append('|').append(dimensions.height); + 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 @@ -1096,6 +1098,10 @@ public class FileBackend { public int getMin() { return Math.min(width, height); } + + public boolean valid() { + return width > 0 && height > 0; + } } private static class NotAVideoFile extends Exception { diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index 148d96bb3..a14e1057b 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -924,9 +924,7 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie } else { displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first, darkBackground); } - } else if (message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) { - displayImageMessage(viewHolder, message); - } else if (message.getType() == Message.TYPE_FILE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) { + } else if (message.isFileOrImage() && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) { if (message.getFileParams().width > 0 && message.getFileParams().height > 0) { displayImageMessage(viewHolder, message); } else if (message.getFileParams().runtime > 0) { -- cgit v1.2.3