Skip to content

Commit

Permalink
Strip EXIF metadata from all JPEG images.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greyson-signal authored and moxie0 committed Mar 31, 2018
1 parent 10e5b24 commit 7e1e666
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/org/thoughtcrime/securesms/jobs/MmsSendJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private SendReq constructSendPdu(OutgoingMediaMessage message)
String lineNumber = getMyNumber(context);
Address destination = message.getRecipient().getAddress();
MediaConstraints mediaConstraints = MediaConstraints.getMmsMediaConstraints(message.getSubscriptionId());
List<Attachment> scaledAttachments = scaleAttachments(mediaConstraints, message.getAttachments());
List<Attachment> scaledAttachments = scaleAndStripExifFromAttachments(mediaConstraints, message.getAttachments());

if (!TextUtils.isEmpty(lineNumber)) {
req.setFrom(new EncodedStringValue(lineNumber));
Expand Down
2 changes: 1 addition & 1 deletion src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void deliver(OutgoingMediaMessage message, @Nullable Address filterAddre
Optional<byte[]> profileKey = getProfileKey(message.getRecipient());
List<Address> recipients = getGroupMessageRecipients(groupId, messageId);
MediaConstraints mediaConstraints = MediaConstraints.getPushMediaConstraints();
List<Attachment> scaledAttachments = scaleAttachments(mediaConstraints, message.getAttachments());
List<Attachment> scaledAttachments = scaleAndStripExifFromAttachments(mediaConstraints, message.getAttachments());
List<SignalServiceAttachment> attachmentStreams = getAttachmentsFor(scaledAttachments);

List<SignalServiceAddress> addresses;
Expand Down
2 changes: 1 addition & 1 deletion src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void deliver(OutgoingMediaMessage message)
try {
SignalServiceAddress address = getPushAddress(message.getRecipient().getAddress());
MediaConstraints mediaConstraints = MediaConstraints.getPushMediaConstraints();
List<Attachment> scaledAttachments = scaleAttachments(mediaConstraints, message.getAttachments());
List<Attachment> scaledAttachments = scaleAndStripExifFromAttachments(mediaConstraints, message.getAttachments());
List<SignalServiceAttachment> attachmentStreams = getAttachmentsFor(scaledAttachments);
Optional<byte[]> profileKey = getProfileKey(message.getRecipient());
SignalServiceDataMessage mediaMessage = SignalServiceDataMessage.newBuilder()
Expand Down
12 changes: 9 additions & 3 deletions src/org/thoughtcrime/securesms/jobs/SendJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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;

Expand Down Expand Up @@ -50,8 +51,8 @@ protected void markAttachmentsUploaded(long messageId, @NonNull List<Attachment>
}
}

protected List<Attachment> scaleAttachments(@NonNull MediaConstraints constraints,
@NonNull List<Attachment> attachments)
protected List<Attachment> scaleAndStripExifFromAttachments(@NonNull MediaConstraints constraints,
@NonNull List<Attachment> attachments)
throws UndeliverableMessageException
{
AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
Expand All @@ -60,7 +61,12 @@ protected List<Attachment> scaleAttachments(@NonNull MediaConstraints constraint
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));
Expand Down
8 changes: 8 additions & 0 deletions src/org/thoughtcrime/securesms/util/MediaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ public static boolean isGif(Attachment attachment) {
return isGif(attachment.getContentType());
}

public static boolean isJpeg(Attachment attachment) {
return isJpegType(attachment.getContentType());
}

public static boolean isImage(Attachment attachment) {
return isImageType(attachment.getContentType());
}
Expand All @@ -169,6 +173,10 @@ public static boolean isGif(String contentType) {
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);
}
Expand Down

0 comments on commit 7e1e666

Please sign in to comment.