be safer when processing parts in AttachmentDownloadJob

Closes #4166
// FREEBIE
This commit is contained in:
Jake McGinty
2015-10-01 12:28:29 -07:00
committed by Moxie Marlinspike
parent c6abb7dc64
commit cdf982a356
5 changed files with 93 additions and 7 deletions

View File

@@ -15,6 +15,7 @@ import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
import org.thoughtcrime.securesms.jobs.requirements.MediaNetworkRequirement;
import org.thoughtcrime.securesms.notifications.MessageNotifier;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.VisibleForTesting;
import org.whispersystems.jobqueue.JobParameters;
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
import org.whispersystems.libaxolotl.InvalidMessageException;
@@ -122,10 +123,16 @@ public class AttachmentDownloadJob extends MasterSecretJob implements Injectable
}
}
private TextSecureAttachmentPointer createAttachmentPointer(MasterSecret masterSecret, PduPart part)
@VisibleForTesting
TextSecureAttachmentPointer createAttachmentPointer(MasterSecret masterSecret, PduPart part)
throws InvalidPartException
{
if (part.getContentLocation() == null) throw new InvalidPartException("null content location");
if (part.getContentLocation() == null || part.getContentLocation().length == 0) {
throw new InvalidPartException("empty content id");
}
if (part.getContentDisposition() == null || part.getContentDisposition().length == 0) {
throw new InvalidPartException("empty encrypted key");
}
try {
AsymmetricMasterSecret asymmetricMasterSecret = MasterSecretUtil.getAsymmetricMasterSecret(context, masterSecret);
@@ -164,7 +171,7 @@ public class AttachmentDownloadJob extends MasterSecretJob implements Injectable
}
}
private static class InvalidPartException extends Exception {
@VisibleForTesting static class InvalidPartException extends Exception {
public InvalidPartException(String s) {super(s);}
public InvalidPartException(Exception e) {super(e);}
}