Throw error if incoming attachment has mismatched attachment size

This commit is contained in:
Scott Nonnenberg 2019-02-15 13:43:22 -08:00
parent f5af063191
commit 7c4ba5446c

View file

@ -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,