Skip to content

Commit b47b7ab

Browse files
Zachary Whitleyvados-cosmonic
authored andcommitted
fix(p2-shim): coerce browser file read bounds to numbers
wasi-filesystem read takes filesize (u64) arguments, which the canonical-ABI binding passes as BigInt. Uint8Array.slice rejects BigInt and throws "Cannot convert a BigInt value to a number" on the first read against any file in the browser implementation: TypeError: Cannot convert a BigInt value to a number at Uint8Array.slice (<anonymous>) at Descriptor.read (preview2-shim/lib/browser/filesystem.js:191) Coerce both arguments to Number on entry. Safe up to Number.MAX_SAFE_INTEGER bytes (~9 PB), well above any practical browser use. Signed-off-by: Zachary Whitley <zachary.whitley@tegmentum.ai>
1 parent 07f7d53 commit b47b7ab

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

packages/preview2-shim/lib/browser/filesystem.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ class Descriptor {
188188

189189
read(length, offset) {
190190
const source = getSource(this.#entry);
191-
return [source.slice(offset, offset + length), offset + length >= source.byteLength];
191+
const off = typeof offset === "bigint" ? Number(offset) : offset;
192+
const len = typeof length === "bigint" ? Number(length) : length;
193+
return [source.slice(off, off + len), off + len >= source.byteLength];
192194
}
193195

194196
write(buffer, offset) {

0 commit comments

Comments
 (0)