1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-18 17:02:27 +02:00

Fix access to detached buffer when using WASM in bidi-trie

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/764

WebAssembly.Memory.grow() preserves the buffer content when
we grow it, no need to manually copy it. Doing so was
causing an access to a no longer valid ArrayBuffer.
This commit is contained in:
Raymond Hill 2019-10-26 17:37:47 -04:00
parent 0373410635
commit c71624d1da
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -759,6 +759,14 @@ const roundToPageSize = v => (v + PAGE_SIZE-1) & ~(PAGE_SIZE-1);
let newBuf;
if ( this.wasmMemory === null ) {
newBuf = new Uint8Array(bufLen);
newBuf.set(this.buf8.subarray(0, this.buf32[TRIE1_SLOT]), 0);
newBuf.set(
this.buf8.subarray(
this.buf32[CHAR0_SLOT],
this.buf32[CHAR1_SLOT]
),
char0
);
} else {
const oldPageCount = this.buf8.length >>> 16;
const newPageCount = (bufLen + 0xFFFF) >>> 16;
@ -767,14 +775,6 @@ const roundToPageSize = v => (v + PAGE_SIZE-1) & ~(PAGE_SIZE-1);
}
newBuf = new Uint8Array(this.wasmMemory.buffer);
}
newBuf.set(this.buf8.subarray(0, this.buf32[TRIE1_SLOT]), 0);
newBuf.set(
this.buf8.subarray(
this.buf32[CHAR0_SLOT],
this.buf32[CHAR1_SLOT]
),
char0
);
this.buf8 = newBuf;
this.buf32 = new Uint32Array(this.buf8.buffer);
this.buf32[CHAR0_SLOT] = char0;