sqlite: reject non-positive backup rates

Passing a rate of 0 to backup() causes sqlite3_backup_step() to copy
no pages. The backup job then continually reschedules itself and the
returned promise never settles.

Require backup rates to be positive integers to prevent zero-work
backup jobs.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: codex:gpt-5.6-sol
PR-URL: https://github.com/nodejs/node/pull/64893
Fixes: https://github.com/nodejs/node/issues/64892
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Trivikram Kamat authored and Antoine du Hamel committed 2026-08-26 00:55:37 +02:00
1 parent aa3b598e2e
commit 06b1758dcd
3 files changed
+16 -1

No files matched your search

+1 -1
View File
@@ -1366,7 +1366,7 @@ changes:
database that have been added with [`ATTACH DATABASE`][] **Default:** `'main'`.
* `target` {string} Name of the target database. This can be `'main'` (the default primary database) or any other
database that have been added with [`ATTACH DATABASE`][] **Default:** `'main'`.
* `rate` {number} Number of pages to be transmitted in each batch of the backup. **Default:** `100`.
* `rate` {integer} Positive number of pages to be transmitted in each batch of the backup. **Default:** `100`.
* `progress` {Function} An optional callback function that will be called after each backup step. The argument passed
to this callback is an {Object} with `remainingPages` and `totalPages` properties, describing the current progress
of the backup operation.
+6
View File
@@ -2200,6 +2200,12 @@ void Backup(const FunctionCallbackInfo<Value>& args) {
return;
}
rate = rate_v.As<Int32>()->Value();
if (rate <= 0) {
THROW_ERR_OUT_OF_RANGE(
env->isolate(),
"The \"options.rate\" argument must be a positive integer.");
return;
}
}
Local<Value> source_v;
+9
View File
@@ -124,6 +124,15 @@ describe('backup()', () => {
message: 'The "options.rate" argument must be an integer.'
});
for (const rate of [0, -1]) {
t.assert.throws(() => {
backup(database, 'hello.db', { rate });
}, {
code: 'ERR_OUT_OF_RANGE',
message: 'The "options.rate" argument must be a positive integer.'
});
}
t.assert.throws(() => {
backup(database, 'hello.db', {
progress: 'invalid'