mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-11-23 22:15:52 +00:00
Fix zlib compression for data larger than 65KB
Regression introduced in https://github.com/openpgpjs/openpgpjs/pull/1826 (v6.2.0) . Due to internal fflate lib changes, part of the compressed data ended up being discarded, leading to a corrupted compressed payload for the encrypted/signed message, which cannot be decompressed. Compression is disabled by default in openpgpjs. Hence, the issue affects only users who enabled zlib compression via e.g. `config.preferredCompressionAlgorithm = openpgp.enums.compression.zlib` and encrypted or signed data larger than 65KB.
This commit is contained in:
parent
30ce607245
commit
0ab548cb90
@ -151,8 +151,12 @@ function zlib(compressionStreamInstantiator, ZlibStreamedConstructor) {
|
||||
return streamFromAsync(() => streamReadToEnd(data).then(inputData => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const zlibStream = new ZlibStreamedConstructor();
|
||||
zlibStream.ondata = processedData => {
|
||||
resolve(processedData);
|
||||
const processedChunks = [];
|
||||
zlibStream.ondata = (processedData, final) => {
|
||||
processedChunks.push(processedData);
|
||||
if (final) {
|
||||
resolve(util.concatUint8Array(processedChunks));
|
||||
}
|
||||
};
|
||||
try {
|
||||
zlibStream.push(inputData, true); // only one chunk to push
|
||||
|
||||
@ -3698,6 +3698,26 @@ XfA3pqV4mTzF
|
||||
});
|
||||
});
|
||||
|
||||
it('should encrypt and decrypt with one password (larger message)', async function () {
|
||||
const largerPlaintext = new Uint8Array(100_000);
|
||||
const encOpt = modifyCompressionEncryptOptions({
|
||||
message: await openpgp.createMessage({ binary: largerPlaintext }),
|
||||
passwords: password1
|
||||
});
|
||||
const decOpt = {
|
||||
passwords: password1,
|
||||
format: 'binary'
|
||||
};
|
||||
return openpgp.encrypt(encOpt).then(async function (encrypted) {
|
||||
decOpt.message = await openpgp.readMessage({ armoredMessage: encrypted });
|
||||
return openpgp.decrypt(decOpt);
|
||||
}).then(function (decrypted) {
|
||||
expect(util.equalsUint8Array(decrypted.data, largerPlaintext)).to.be.true;
|
||||
expect(decrypted.signatures.length).to.equal(0);
|
||||
verifyCompressionDecrypted(decrypted);
|
||||
});
|
||||
});
|
||||
|
||||
it('Streaming encrypt and decrypt small message roundtrip', async function() {
|
||||
const plaintext = [];
|
||||
let i = 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user