Megolm import: Fix handling of short files
Make sure we throw a sensible error when the body of the data is too short.
This commit is contained in:
parent
62c8c20268
commit
c5f447260a
2 changed files with 11 additions and 1 deletions
|
@ -50,7 +50,7 @@ export function decryptMegolmKeyFile(data, password) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const ciphertextLength = body.length-(1+16+16+4+32);
|
const ciphertextLength = body.length-(1+16+16+4+32);
|
||||||
if (body.length < 0) {
|
if (ciphertextLength < 0) {
|
||||||
throw new Error('Invalid file: too short');
|
throw new Error('Invalid file: too short');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,16 @@ describe('MegolmExportEncryption', function() {
|
||||||
.toThrow('Trailer line not found');
|
.toThrow('Trailer line not found');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle a too-short body', function() {
|
||||||
|
const input=stringToArray(`-----BEGIN MEGOLM SESSION DATA-----
|
||||||
|
AXNhbHRzYWx0c2FsdHNhbHSIiIiIiIiIiIiIiIiIiIiIAAAACmIRUW2OjZ3L2l6j9h0lHlV3M2dx
|
||||||
|
cissyYBxjsfsAn
|
||||||
|
-----END MEGOLM SESSION DATA-----
|
||||||
|
`);
|
||||||
|
expect(()=>{MegolmExportEncryption.decryptMegolmKeyFile(input, '')})
|
||||||
|
.toThrow('Invalid file: too short');
|
||||||
|
});
|
||||||
|
|
||||||
it('should decrypt a range of inputs', function(done) {
|
it('should decrypt a range of inputs', function(done) {
|
||||||
function next(i) {
|
function next(i) {
|
||||||
if (i >= TEST_VECTORS.length) {
|
if (i >= TEST_VECTORS.length) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue