Throw error if incoming attachment has mismatched attachment size

pull/272/head
Scott Nonnenberg 6 years ago
parent f5af063191
commit 7c4ba5446c

@ -1216,7 +1216,7 @@ MessageReceiver.prototype.extend({
},
async downloadAttachment(attachment) {
const encrypted = await this.server.getAttachment(attachment.id);
const { key, digest } = attachment;
const { key, digest, size } = attachment;
const data = await textsecure.crypto.decryptAttachment(
encrypted,
@ -1224,6 +1224,14 @@ MessageReceiver.prototype.extend({
window.Signal.Crypto.base64ToArrayBuffer(digest)
);
if (!size || size !== data.byteLength) {
throw new Error(
`downloadAttachment: Size ${size} did not match downloaded attachment size ${
data.byteLength
}`
);
}
return {
..._.omit(attachment, 'digest', 'key'),
data,

Loading…
Cancel
Save