Repository navigation
fix: allocate SQL on the heap in Database.run and Database.prepare - #639
Merged
Merged
Conversation
Both passed the SQL to SQLite as a cwrap string, which Emscripten copies onto the 5 MB WebAssembly stack. SQL longer than that overwrote memory and left the database unusable. exec() and the statement iterator already allocate the SQL on the heap, so do the same here.
lovasoa
approved these changes
Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #482
Database.runandDatabase.preparepass the SQL to SQLite as a cwrap"string"argument, which Emscripten copies onto the 5 MB WebAssembly stack. SQL longer than that writes past the stack, so the call throwsmemory access out of boundsand every later sql.js call fails too. People hit this running a largeINSERTor a SQL dump throughdb.run.execandStatementIteratoralready put the SQL on the heap withstringToNewUTF8and free it in afinally.run(the no-params path) andpreparenow do the same, and I dropped the string-typedsqlite3_prepare_v2wrapper since nothing uses it.Added
test_issue482.js, which runs a 6 MiBINSERTthroughrun,runwith params andprepare.npm testpasses.Assisted by Claude/Codex.