Improve attachment field validation.

This commit is contained in:
Greyson Parrelli
2026-07-27 14:56:46 -04:00
committed by Michelle Tang
parent 7ea3679a24
commit 3e8190637c
@@ -7,7 +7,6 @@ import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemo
import org.whispersystems.signalservice.internal.push.AttachmentPointer;
import java.io.IOException;
import java.util.Objects;
import java.util.Optional;
import okio.ByteString;
@@ -18,10 +17,18 @@ public final class AttachmentPointerUtil {
}
public static SignalServiceAttachmentPointer createSignalAttachmentPointer(AttachmentPointer pointer) throws InvalidMessageStructureException {
return new SignalServiceAttachmentPointer(Objects.requireNonNull(pointer.cdnNumber),
if (pointer.cdnNumber == null) {
throw new InvalidMessageStructureException("AttachmentPointer CDN number not set");
}
if (pointer.key == null) {
throw new InvalidMessageStructureException("AttachmentPointer key not set");
}
return new SignalServiceAttachmentPointer(pointer.cdnNumber,
SignalServiceAttachmentRemoteId.from(pointer),
pointer.contentType,
Objects.requireNonNull(pointer.key).toByteArray(),
pointer.key.toByteArray(),
pointer.size != null ? Optional.of(pointer.size) : Optional.empty(),
pointer.thumbnail != null ? Optional.of(pointer.thumbnail.toByteArray()): Optional.empty(),
pointer.width != null ? pointer.width : 0,