Fix attachment pointer crash when missing incremental digest.

This commit is contained in:
Cody Henthorne 2023-07-21 19:54:57 -04:00
parent f5fc2acf50
commit 8c1f2c6064
4 changed files with 9 additions and 7 deletions

View file

@ -113,7 +113,7 @@ public class PointerAttachment extends Attachment {
pointer.get().asPointer().getRemoteId().toString(),
encodedKey, null,
pointer.get().asPointer().getDigest().orElse(null),
pointer.get().asPointer().getincrementalDigest().orElse(null),
pointer.get().asPointer().getIncrementalDigest().orElse(null),
fastPreflightId,
pointer.get().asPointer().getVoiceNote(),
pointer.get().asPointer().isBorderless(),
@ -139,7 +139,7 @@ public class PointerAttachment extends Attachment {
thumbnail != null && thumbnail.asPointer().getKey() != null ? Base64.encodeBytes(thumbnail.asPointer().getKey()) : null,
null,
thumbnail != null ? thumbnail.asPointer().getDigest().orElse(null) : null,
thumbnail != null ? thumbnail.asPointer().getincrementalDigest().orElse(null) : null,
thumbnail != null ? thumbnail.asPointer().getIncrementalDigest().orElse(null) : null,
null,
false,
false,
@ -169,7 +169,7 @@ public class PointerAttachment extends Attachment {
thumbnail != null && thumbnail.asPointer().getKey() != null ? Base64.encodeBytes(thumbnail.asPointer().getKey()) : null,
null,
thumbnail != null ? thumbnail.asPointer().getDigest().orElse(null) : null,
thumbnail != null ? thumbnail.asPointer().getincrementalDigest().orElse(null) : null,
thumbnail != null ? thumbnail.asPointer().getIncrementalDigest().orElse(null) : null,
null,
false,
false,

View file

@ -36,7 +36,6 @@ import org.whispersystems.signalservice.internal.util.concurrent.FutureTransform
import org.whispersystems.signalservice.internal.util.concurrent.ListenableFuture;
import org.whispersystems.signalservice.internal.websocket.ResponseMapper;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -154,7 +153,7 @@ public class SignalServiceMessageReceiver {
if (!pointer.getDigest().isPresent()) throw new InvalidMessageException("No attachment digest!");
socket.retrieveAttachment(pointer.getCdnNumber(), pointer.getRemoteId(), destination, maxSizeBytes, listener);
return AttachmentCipherInputStream.createForAttachment(destination, pointer.getSize().orElse(0), pointer.getKey(), pointer.getDigest().get(), pointer.getincrementalDigest().orElse(new byte[0]));
return AttachmentCipherInputStream.createForAttachment(destination, pointer.getSize().orElse(0), pointer.getKey(), pointer.getDigest().get(), pointer.getIncrementalDigest().orElse(new byte[0]));
}
public InputStream retrieveSticker(byte[] packId, byte[] packKey, int stickerId)

View file

@ -111,7 +111,7 @@ public class SignalServiceAttachmentPointer extends SignalServiceAttachment {
return digest;
}
public Optional<byte[]> getincrementalDigest() {
public Optional<byte[]> getIncrementalDigest() {
return incrementalDigest;
}

View file

@ -42,10 +42,13 @@ public final class AttachmentPointerUtil {
.setContentType(attachment.getContentType())
.setKey(ByteString.copyFrom(attachment.getKey()))
.setDigest(ByteString.copyFrom(attachment.getDigest().get()))
.setIncrementalDigest(ByteString.copyFrom(attachment.getincrementalDigest().get()))
.setSize(attachment.getSize().get())
.setUploadTimestamp(attachment.getUploadTimestamp());
if (attachment.getIncrementalDigest().isPresent()) {
builder.setIncrementalDigest(ByteString.copyFrom(attachment.getIncrementalDigest().get()));
}
if (attachment.getRemoteId().getV2().isPresent()) {
builder.setCdnId(attachment.getRemoteId().getV2().get());
}