Skip to content

Commit

Permalink
Throw error if incoming attachment has mismatched attachment size
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Feb 21, 2019
1 parent f5af063 commit 7c4ba54
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion libtextsecure/message_receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1216,14 +1216,22 @@ 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,
window.Signal.Crypto.base64ToArrayBuffer(key),
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,
Expand Down

0 comments on commit 7c4ba54

Please sign in to comment.