tndrle / node-sqlite3-wasm

WebAssembly port of SQLite3 for Node.js with file system access
MIT License
55 stars 8 forks source link

Table index is out of bounds error #30

Closed fabiospampinato closed 10 months ago

fabiospampinato commented 10 months ago

It seems that large-ish blobs (bigger than ~64kb) can't be put into a table, I'm not sure where the error is, but this should reproduce the error:

import * as Sqlite3Wasm from 'node-sqlite3-wasm';
const Database = Sqlite3Wasm.default.Database;

const SAMPLE = new TextEncoder ().encode ( 'a'.repeat ( 100_000 ) );

const wdb = new Database ( ':memory:' );

await wdb.exec ( `CREATE TABLE example ( id INTEGER PRIMARY KEY, data BLOB )` );
await wdb.prepare ( `INSERT INTO example VALUES( ?, ? )` ).run ([ 1, SAMPLE ]);

const read = await wdb.all ( `SELECT data FROM example WHERE id=1` );

await wdb.exec ( `DELETE FROM example WHERE id=1` );

And error is this:

wasm://wasm/0039d32e:1

RuntimeError: table index is out of bounds
    at wasm://wasm/0039d32e:wasm-function[285]:0x5341e
    at wasm://wasm/0039d32e:wasm-function[411]:0x79401
    at wasm://wasm/0039d32e:wasm-function[784]:0xc1ddc
    at ccall (/Users/fabio/Code/fabiospampinato/tiny-sqlite3/node_modules/node-sqlite3-wasm/dist/node-sqlite3-wasm.js:8:29808)
    at /Users/fabio/Code/fabiospampinato/tiny-sqlite3/node_modules/node-sqlite3-wasm/dist/node-sqlite3-wasm.js:8:30193
    at Statement._bindValue (/Users/fabio/Code/fabiospampinato/tiny-sqlite3/node_modules/node-sqlite3-wasm/dist/node-sqlite3-wasm.js:8:12466)
    at Statement._bindArray (/Users/fabio/Code/fabiospampinato/tiny-sqlite3/node_modules/node-sqlite3-wasm/dist/node-sqlite3-wasm.js:8:11500)
    at Statement._bind (/Users/fabio/Code/fabiospampinato/tiny-sqlite3/node_modules/node-sqlite3-wasm/dist/node-sqlite3-wasm.js:8:10208)
    at Statement.run (/Users/fabio/Code/fabiospampinato/tiny-sqlite3/node_modules/node-sqlite3-wasm/dist/node-sqlite3-wasm.js:8:9263)
    at file:///Users/fabio/Code/fabiospampinato/tiny-sqlite3/tasks/blob.js:61:60

Node.js v18.12.0

Could this be fixed?

tndrle commented 10 months ago

Thanks for reporting this. It is a problem with emscripten's fixed stack size I think. I'll look into it. (see https://github.com/emscripten-core/emscripten/issues/4344 and https://github.com/emscripten-core/emscripten/issues/6860)

tndrle commented 10 months ago

v0.6.9 is out and should fix this issue