From 7e1e666172e0c8d0582d28a817affae91a02a598 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Mon, 19 Mar 2018 11:22:39 -0700 Subject: [PATCH] Strip EXIF metadata from all JPEG images. Strip all EXIF metadata from all JPEGs by re-encoding the JPEG. This will keep all of the necessary visual effects of the tags (by encoding them directly in the image data) while stripped the EXIF tags themselves. --- src/org/thoughtcrime/securesms/jobs/MmsSendJob.java | 2 +- .../securesms/jobs/PushGroupSendJob.java | 2 +- .../securesms/jobs/PushMediaSendJob.java | 2 +- src/org/thoughtcrime/securesms/jobs/SendJob.java | 12 +++++++++--- src/org/thoughtcrime/securesms/util/MediaUtil.java | 8 ++++++++ 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/jobs/MmsSendJob.java b/src/org/thoughtcrime/securesms/jobs/MmsSendJob.java index 51bf70ae4a..b0a92a0b92 100644 --- a/src/org/thoughtcrime/securesms/jobs/MmsSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/MmsSendJob.java @@ -175,7 +175,7 @@ public class MmsSendJob extends SendJob { String lineNumber = getMyNumber(context); Address destination = message.getRecipient().getAddress(); MediaConstraints mediaConstraints = MediaConstraints.getMmsMediaConstraints(message.getSubscriptionId()); - List scaledAttachments = scaleAttachments(mediaConstraints, message.getAttachments()); + List scaledAttachments = scaleAndStripExifFromAttachments(mediaConstraints, message.getAttachments()); if (!TextUtils.isEmpty(lineNumber)) { req.setFrom(new EncodedStringValue(lineNumber)); diff --git a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java index f87da858a1..908ca6a1d3 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java @@ -141,7 +141,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType { Optional profileKey = getProfileKey(message.getRecipient()); List
recipients = getGroupMessageRecipients(groupId, messageId); MediaConstraints mediaConstraints = MediaConstraints.getPushMediaConstraints(); - List scaledAttachments = scaleAttachments(mediaConstraints, message.getAttachments()); + List scaledAttachments = scaleAndStripExifFromAttachments(mediaConstraints, message.getAttachments()); List attachmentStreams = getAttachmentsFor(scaledAttachments); List addresses; diff --git a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java index d357e9e341..1e40186a2c 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java @@ -107,7 +107,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType { try { SignalServiceAddress address = getPushAddress(message.getRecipient().getAddress()); MediaConstraints mediaConstraints = MediaConstraints.getPushMediaConstraints(); - List scaledAttachments = scaleAttachments(mediaConstraints, message.getAttachments()); + List scaledAttachments = scaleAndStripExifFromAttachments(mediaConstraints, message.getAttachments()); List attachmentStreams = getAttachmentsFor(scaledAttachments); Optional profileKey = getProfileKey(message.getRecipient()); SignalServiceDataMessage mediaMessage = SignalServiceDataMessage.newBuilder() diff --git a/src/org/thoughtcrime/securesms/jobs/SendJob.java b/src/org/thoughtcrime/securesms/jobs/SendJob.java index f07300e46b..6b03b2935a 100644 --- a/src/org/thoughtcrime/securesms/jobs/SendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/SendJob.java @@ -13,6 +13,7 @@ import org.thoughtcrime.securesms.mms.MediaConstraints; import org.thoughtcrime.securesms.mms.MediaStream; import org.thoughtcrime.securesms.mms.MmsException; import org.thoughtcrime.securesms.transport.UndeliverableMessageException; +import org.thoughtcrime.securesms.util.MediaUtil; import org.thoughtcrime.securesms.util.Util; import org.whispersystems.jobqueue.JobParameters; @@ -50,8 +51,8 @@ public abstract class SendJob extends MasterSecretJob { } } - protected List scaleAttachments(@NonNull MediaConstraints constraints, - @NonNull List attachments) + protected List scaleAndStripExifFromAttachments(@NonNull MediaConstraints constraints, + @NonNull List attachments) throws UndeliverableMessageException { AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context); @@ -60,7 +61,12 @@ public abstract class SendJob extends MasterSecretJob { for (Attachment attachment : attachments) { try { if (constraints.isSatisfied(context, attachment)) { - results.add(attachment); + if (MediaUtil.isJpeg(attachment)) { + MediaStream stripped = constraints.getResizedMedia(context, attachment); + results.add(attachmentDatabase.updateAttachmentData(attachment, stripped)); + } else { + results.add(attachment); + } } else if (constraints.canResize(attachment)) { MediaStream resized = constraints.getResizedMedia(context, attachment); results.add(attachmentDatabase.updateAttachmentData(attachment, resized)); diff --git a/src/org/thoughtcrime/securesms/util/MediaUtil.java b/src/org/thoughtcrime/securesms/util/MediaUtil.java index 400448df83..e284e0a4fa 100644 --- a/src/org/thoughtcrime/securesms/util/MediaUtil.java +++ b/src/org/thoughtcrime/securesms/util/MediaUtil.java @@ -149,6 +149,10 @@ public class MediaUtil { return isGif(attachment.getContentType()); } + public static boolean isJpeg(Attachment attachment) { + return isJpegType(attachment.getContentType()); + } + public static boolean isImage(Attachment attachment) { return isImageType(attachment.getContentType()); } @@ -169,6 +173,10 @@ public class MediaUtil { return !TextUtils.isEmpty(contentType) && contentType.trim().equals("image/gif"); } + public static boolean isJpegType(String contentType) { + return !TextUtils.isEmpty(contentType) && contentType.trim().equals(IMAGE_JPEG); + } + public static boolean isFile(Attachment attachment) { return !isGif(attachment) && !isImage(attachment) && !isAudio(attachment) && !isVideo(attachment); }