Manually calculate attachment offsets

The CipherInputStream skip() method is pretty non-functional

Fixes #7438
This commit is contained in:
Moxie Marlinspike
2018-02-24 11:09:26 -08:00
parent 4324f0b7ec
commit 028c6edd8a
7 changed files with 48 additions and 39 deletions

View File

@@ -58,13 +58,9 @@ public class EncryptedMediaDataSource extends MediaDataSource {
private int readAtModern(long position, byte[] bytes, int offset, int length) throws IOException {
assert(random != null);
InputStream inputStream = ModernDecryptingPartInputStream.createFor(attachmentSecret, random, mediaFile);
InputStream inputStream = ModernDecryptingPartInputStream.createFor(attachmentSecret, random, mediaFile, position);
int returnValue = inputStream.read(bytes, offset, length);
if (inputStream.skip(position) != position) {
throw new IOException("Skip failed: " + position);
}
int returnValue = inputStream.read(bytes, offset, length);
inputStream.close();
return returnValue;

View File

@@ -11,7 +11,6 @@ import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.TransferListener;
import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.AttachmentDatabase;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.mms.PartUriParser;
@@ -28,8 +27,7 @@ public class PartDataSource implements DataSource {
private Uri uri;
private InputStream inputSteam;
public PartDataSource(@NonNull Context context, @Nullable TransferListener<? super PartDataSource> listener)
{
PartDataSource(@NonNull Context context, @Nullable TransferListener<? super PartDataSource> listener) {
this.context = context.getApplicationContext();
this.listener = listener;
}
@@ -44,13 +42,7 @@ public class PartDataSource implements DataSource {
if (attachment == null) throw new IOException("Attachment not found");
this.inputSteam = attachmentDatabase.getAttachmentStream(partUri.getPartId());
if (inputSteam == null) throw new IOException("InputStream not foudn");
long skipped = this.inputSteam.skip(dataSpec.position);
if (skipped != dataSpec.position) throw new IOException("Skip failed!");
this.inputSteam = attachmentDatabase.getAttachmentStream(partUri.getPartId(), dataSpec.position);
if (listener != null) {
listener.onTransferStart(this, dataSpec);