mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-11 17:41:03 +01: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:
parent
0ccbe654b8
commit
651955b97c
2 changed files with 11 additions and 4 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue