GeezerVison is showing github.com — sqlite: reject reentry while binding parameters by TrevorBurnham · Pull Request #65294 · nodejs/node
Conversation
Follow-up for #65156. That PR added tracking for the statements currently being stepped and rejects reentry into them. The guard is established inside the execution helpers, though, which the entry points reach only after resetting the statement and binding its parameters.
Binding reads properties off the supplied object, so a named-parameter getter runs JavaScript in that window. On current main:
const { DatabaseSync } = require('node:sqlite');
const db = new DatabaseSync(':memory:');
db.exec('CREATE TABLE data (value INTEGER); INSERT INTO data VALUES (1),(2),(3);');
const st = db.prepare('SELECT value FROM data WHERE value >= $min');
let inner;
const params = { get $min() { inner ??= st.iterate({ $min: 1 }); return 1; } };
const outer = st.iterate(params);
console.log(outer.next(), inner.next(), outer.next(), inner.next());
{ done: false, value: { value: 1 } } // outer
{ done: false, value: { value: 2 } } // inner
{ done: false, value: { value: 3 } } // outer
{ done: true, value: null } // inner
Two live iterators over one virtual machine. The reset-generation check does not catch it because the inner iterate() bumps the generation before the outer iterator is constructed, so both record the same value and neither is invalidated.
This PR hoists the guard to the four StatementSync entry points, before the reset, so it spans binding as well as stepping. The guards inside the helpers are left alone; stepping_statements_ is a stack, so the nested acquisition is balanced. It also adds test cases salvaged from #65106, which was superseded by #65156.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
c4b755e tracks the statements currently being stepped and rejects
reentry into them, but the guard is established inside the execution
helpers, after the entry point has already reset the statement and
bound its parameters. Binding reads properties off the supplied
object, so a named-parameter getter runs JavaScript in that window.
Reentering the same statement there resets it a second time and, for
iterate(), hands out a second iterator; both iterators record the
same reset generation, so neither is invalidated and they interleave
rows from one virtual machine.
Establish the guard at the four StatementSync entry points instead,
before the reset, so it spans binding as well as stepping. The
existing guards inside the helpers are left in place; the stepping
set is a stack, so the nested acquisition is balanced.
Signed-off-by: Trevor Burnham <[email protected]>
Assisted-by: claude:opus-5
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
codecov
Bot
commented
Aug 15, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.30%. Comparing base (c8996ea) to head (58b955d).
⚠️ Report is 99 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #65294 +/- ##
==========================================
- Coverage 90.33% 90.30% -0.03%
==========================================
Files 751 751
Lines 250048 250239 +191
Branches 47254 47300 +46
==========================================
+ Hits 225877 225990 +113
- Misses 15553 15620 +67
- Partials 8618 8629 +11
... and 39 files with indirect coverage changes
🚀 New features to boost your workflow:
- ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
aduh95
pushed a commit
that referenced
this pull request
Aug 25, 2026
c4b755e tracks the statements currently being stepped and rejects
reentry into them, but the guard is established inside the execution
helpers, after the entry point has already reset the statement and
bound its parameters. Binding reads properties off the supplied
object, so a named-parameter getter runs JavaScript in that window.
Reentering the same statement there resets it a second time and, for
iterate(), hands out a second iterator; both iterators record the
same reset generation, so neither is invalidated and they interleave
rows from one virtual machine.
Establish the guard at the four StatementSync entry points instead,
before the reset, so it spans binding as well as stepping. The
existing guards inside the helpers are left in place; the stepping
set is a stack, so the nested acquisition is balanced.
Signed-off-by: Trevor Burnham <[email protected]>
Assisted-by: claude:opus-5
PR-URL: #65294
Reviewed-By: Trivikram Kamat <[email protected]>
aduh95
pushed a commit
that referenced
this pull request
Aug 25, 2026
c4b755e tracks the statements currently being stepped and rejects
reentry into them, but the guard is established inside the execution
helpers, after the entry point has already reset the statement and
bound its parameters. Binding reads properties off the supplied
object, so a named-parameter getter runs JavaScript in that window.
Reentering the same statement there resets it a second time and, for
iterate(), hands out a second iterator; both iterators record the
same reset generation, so neither is invalidated and they interleave
rows from one virtual machine.
Establish the guard at the four StatementSync entry points instead,
before the reset, so it spans binding as well as stepping. The
existing guards inside the helpers are left in place; the stepping
set is a stack, so the nested acquisition is balanced.
Signed-off-by: Trevor Burnham <[email protected]>
Assisted-by: claude:opus-5
PR-URL: #65294
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewers
trivikr
trivikr approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
author ready
PRs with CI started, the required approvals, and no outstanding review comments.
c++
Issues and PRs that require attention from people who are familiar with C++.
needs-ci
PRs that need a full CI run.
sqlite
Issues and PRs related to the SQLite subsystem.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|