Don't zero-copy transfer buffers in Safari 11.1 and Chrome < 56

See https://bugs.webkit.org/show_bug.cgi?id=184254
and https://bugs.chromium.org/p/chromium/issues/detail?id=334408.
This commit is contained in:
Daniel Huigens 2019-01-15 12:24:13 +01:00
parent b904aef3a7
commit 77055f6dfe
3 changed files with 18 additions and 5 deletions

View File

@ -64,7 +64,10 @@ export default {
}
if (util.isUint8Array(obj)) {
if (zero_copy && collection.indexOf(obj.buffer) === -1) {
if (zero_copy && collection.indexOf(obj.buffer) === -1 && !(
navigator.userAgent.indexOf('Version/11.1') !== -1 || // Safari 11.1
((navigator.userAgent.match(/Chrome\/(\d+)/) || [])[1] < 56 && navigator.userAgent.indexOf('Edge') === -1) // Chrome < 56
)) {
collection.push(obj.buffer);
}
return;

View File

@ -1705,7 +1705,11 @@ describe('[Sauce Labs Group 2] OpenPGP.js public api tests', function() {
return openpgp.decrypt(decOpt);
}).then(function (decrypted) {
if (openpgp.getWorker()) {
expect(encOpt.message.packets[0].data.byteLength).to.equal(0); // transferred buffer should be empty
if (navigator.userAgent.indexOf('Safari') !== -1 && (navigator.userAgent.indexOf('Version/11.1') !== -1 || (navigator.userAgent.match(/Chrome\/(\d+)/) || [])[1] < 56)) {
expect(encOpt.message.packets[0].data.byteLength).to.equal(8); // browser doesn't support transfering buffers
} else {
expect(encOpt.message.packets[0].data.byteLength).to.equal(0); // transferred buffer should be empty
}
}
expect(decrypted.data).to.deep.equal(new Uint8Array([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]));
expect(decrypted.signatures.length).to.equal(0);

View File

@ -137,9 +137,15 @@ describe('Util unit tests', function() {
it('should return undefined for an empty oject', function() {
expect(openpgp.util.getTransferables({}, true)).to.be.undefined;
});
it('should return two buffers', function() {
expect(openpgp.util.getTransferables(obj, true)).to.deep.equal([buf1.buffer, buf2.buffer]);
});
if (typeof navigator !== 'undefined') {
it('should return two buffers', function() {
expect(openpgp.util.getTransferables(obj, true)).to.deep.equal(
navigator.userAgent.indexOf('Safari') !== -1 && (navigator.userAgent.indexOf('Version/11.1') !== -1 || (navigator.userAgent.match(/Chrome\/(\d+)/) || [])[1] < 56) ?
undefined :
[buf1.buffer, buf2.buffer]
);
});
}
});
describe("Misc.", function() {