From 2257420523994b6f8f2863da47a695ed299c247e Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 6 Jul 2020 13:57:41 +1000 Subject: [PATCH] ignore other empty buffers which should be null after protobuf decode --- ts/receiver/contentMessage.ts | 13 ++++++++++++- ts/receiver/dataMessage.ts | 9 +++++---- ts/receiver/multidevice.ts | 6 +++++- ts/receiver/receiver.ts | 3 +-- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index b6e73b9e4..b8b6e310a 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -370,7 +370,12 @@ export async function innerHandleContentMessage( } if (content.dataMessage) { - // Are we not supposed to await here? + if ( + content.dataMessage.profileKey && + content.dataMessage.profileKey.length === 0 + ) { + content.dataMessage.profileKey = null; + } await handleDataMessage(envelope, content.dataMessage); return; } @@ -387,6 +392,12 @@ export async function innerHandleContentMessage( return; } if (content.typingMessage) { + if ( + content.typingMessage.groupId && + content.typingMessage.groupId.length === 0 + ) { + content.typingMessage.groupId = null; + } await handleTypingMessage(envelope, content.typingMessage); return; } diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index 67ef1a43a..653075b37 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -83,9 +83,10 @@ function cleanAttachment(attachment: any) { ..._.omit(attachment, 'thumbnail'), id: attachment.id.toString(), key: attachment.key ? StringUtils.decode(attachment.key, 'base64') : null, - digest: attachment.digest - ? StringUtils.decode(attachment.digest, 'base64') - : null, + digest: + attachment.digest && attachment.digest.length > 0 + ? StringUtils.decode(attachment.digest, 'base64') + : null, }; } @@ -138,7 +139,7 @@ function cleanAttachments(decrypted: any) { quote.attachments = (quote.attachments || []).map((item: any) => { const { thumbnail } = item; - if (!thumbnail) { + if (!thumbnail || thumbnail.length === 0) { return item; } diff --git a/ts/receiver/multidevice.ts b/ts/receiver/multidevice.ts index cd39dbab6..4b75cceeb 100644 --- a/ts/receiver/multidevice.ts +++ b/ts/receiver/multidevice.ts @@ -215,6 +215,10 @@ function parseContacts(arrbuf: ArrayBuffer): Array { new Uint8Array(nextBuffer) ); + if (proto.profileKey && proto.profileKey.length === 0) { + proto.profileKey = null; + } + buffer.skip(len); if (proto.avatar) { @@ -259,7 +263,7 @@ export async function handleContacts( window.log.info('contact sync'); // const { blob } = contacts; - if (!contacts.data) { + if (!contacts.data || contacts.data.length === 0) { window.log.error('Contacts without data'); return; } diff --git a/ts/receiver/receiver.ts b/ts/receiver/receiver.ts index 0fdf69fd4..3b50cdb93 100644 --- a/ts/receiver/receiver.ts +++ b/ts/receiver/receiver.ts @@ -48,7 +48,6 @@ interface ReqOptions { const incomingMessagePromises: Array> = []; async function handleEnvelope(envelope: EnvelopePlus) { - const { textsecure } = window; // TODO: enable below // if (this.stoppingProcessing) { @@ -59,7 +58,7 @@ async function handleEnvelope(envelope: EnvelopePlus) { return onDeliveryReceipt(envelope.source, envelope.timestamp); } - if (envelope.content) { + if (envelope.content && envelope.content.length > 0) { return handleContentMessage(envelope); }