1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 07:22:28 +02:00

Throw if mismatched size when unserializing an array buffer

An exception will be thrown if the length of an unserialized
array buffer does not match exactly the original size at
serialization time.
This commit is contained in:
Raymond Hill 2020-02-04 09:55:02 -05:00
parent 0ccbe654b8
commit 651955b97c
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 11 additions and 4 deletions

View File

@ -1020,8 +1020,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
return;
}
} catch (ex) {
console.error(ex);
return;
log.info(ex);
}
const result = await this.assets.get(this.pslAssetKey);

View File

@ -555,16 +555,19 @@
const inbuf = new Uint32Array(arrbuf, 0, inputLength);
const outputLength = this.magic.length + 7 + inputLength * 7;
const outbuf = new Uint8Array(outputLength);
// magic bytes
let j = 0;
for ( let i = 0; i < this.magic.length; i++ ) {
outbuf[j++] = this.magic.charCodeAt(i);
}
// array size
let v = inputLength;
do {
outbuf[j++] = this.valToDigit[v & 0b111111];
v >>>= 6;
} while ( v !== 0 );
outbuf[j++] = 0x20 /* ' ' */;
// array content
for ( let i = 0; i < inputLength; i++ ) {
v = inbuf[i];
do {
@ -596,16 +599,18 @@
throw new Error('Invalid µBlock.base64 encoding');
}
const inputLength = instr.length;
const outputLength = this.decodeSize(instr) >> 2;
const outbuf = arrbuf instanceof ArrayBuffer === false
? new Uint32Array(this.decodeSize(instr) >> 2)
? new Uint32Array(outputLength)
: new Uint32Array(arrbuf);
let i = instr.indexOf(' ', this.magic.length) + 1;
if ( i === -1 ) {
throw new Error('Invalid µBlock.base64 encoding');
}
// array content
let j = 0;
for (;;) {
if ( i === inputLength ) { break; }
if ( j === outputLength || i >= inputLength ) { break; }
let v = 0, l = 0;
for (;;) {
const c = instr.charCodeAt(i++);
@ -615,6 +620,9 @@
}
outbuf[j++] = v;
}
if ( i < inputLength || j < outputLength ) {
throw new Error('Invalid µBlock.base64 encoding');
}
return outbuf;
}