sqlite: fix use-after-free in Exec() and ApplyChangeset()#64535
Open
mcollina wants to merge 1 commit into
Open
sqlite: fix use-after-free in Exec() and ApplyChangeset()#64535mcollina wants to merge 1 commit into
mcollina wants to merge 1 commit into
Conversation
Collaborator
|
Review requested:
|
When sqlite3_exec() or sqlite3changeset_apply() call JavaScript callbacks (user-defined functions, conflict handlers, or filter callbacks), the DatabaseSync object could be garbage-collected if the JavaScript code drops all references to it. Both methods only held a raw DatabaseSync* pointer on the C++ stack, which V8 GC does not track. Add a BaseObjectPtr<DatabaseSync> guard that keeps the database alive for the duration of these SQLite API calls, preventing a use-after-free when the JavaScript callback triggers GC. Signed-off-by: Matteo Collina <hello@matteocollina.com>
5387a80 to
4c6b429
Compare
geeksilva97
approved these changes
Jul 16, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #64535 +/- ##
==========================================
- Coverage 90.23% 90.22% -0.01%
==========================================
Files 741 739 -2
Lines 241681 241669 -12
Branches 45547 45550 +3
==========================================
- Hits 218075 218049 -26
- Misses 15141 15154 +13
- Partials 8465 8466 +1
🚀 New features to boost your workflow:
|
Collaborator
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.
When
sqlite3_exec()orsqlite3changeset_apply()call JavaScriptcallbacks (user-defined functions, conflict handlers, or filter
callbacks), the
DatabaseSyncobject could be garbage-collectedif the JavaScript code drops all references to it. Both methods
only held a raw
DatabaseSync*pointer on the C++ stack, whichV8 GC does not track.
Add a
BaseObjectPtr<DatabaseSync>guard that keeps the databasealive for the duration of these SQLite API calls, preventing a
use-after-free when the JavaScript callback triggers GC.