GeezerVison is showing github.com — sqlite: reject non-positive backup rates · nodejs/node@61a0463
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/api/sqlite.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1326,7 +1326,7 @@ changes: |
1326 | 1326 | database that have been added with [`ATTACH DATABASE`][] **Default:** `'main'`. |
1327 | 1327 | * `target` {string} Name of the target database. This can be `'main'` (the default primary database) or any other |
1328 | 1328 | database that have been added with [`ATTACH DATABASE`][] **Default:** `'main'`. |
1329 | | - * `rate` {number} Number of pages to be transmitted in each batch of the backup. **Default:** `100`. |
| 1329 | + * `rate` {integer} Positive number of pages to be transmitted in each batch of the backup. **Default:** `100`. |
1330 | 1330 | * `progress` {Function} An optional callback function that will be called after each backup step. The argument passed |
1331 | 1331 | to this callback is an {Object} with `remainingPages` and `totalPages` properties, describing the current progress |
1332 | 1332 | of the backup operation. |
|
Collapse file
Copy file name to clipboardExpand all lines: src/node_sqlite.cc +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2180,6 +2180,12 @@ void Backup(const FunctionCallbackInfo<Value>& args) { |
2180 | 2180 | return; |
2181 | 2181 | } |
2182 | 2182 | rate = rate_v.As<Int32>()->Value(); |
| 2183 | + if (rate <= 0) { |
| 2184 | + THROW_ERR_OUT_OF_RANGE( |
| 2185 | + env->isolate(), |
| 2186 | + "The \"options.rate\" argument must be a positive integer."); |
| 2187 | + return; |
| 2188 | + } |
2183 | 2189 | } |
2184 | 2190 |
|
2185 | 2191 | Local<Value> source_v; |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-sqlite-backup.mjs +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -124,6 +124,15 @@ describe('backup()', () => { |
124 | 124 | message: 'The "options.rate" argument must be an integer.' |
125 | 125 | }); |
126 | 126 |
|
| 127 | + for (const rate of [0, -1]) { |
| 128 | + t.assert.throws(() => { |
| 129 | + backup(database, 'hello.db', { rate }); |
| 130 | + }, { |
| 131 | + code: 'ERR_OUT_OF_RANGE', |
| 132 | + message: 'The "options.rate" argument must be a positive integer.' |
| 133 | + }); |
| 134 | + } |
| 135 | + |
127 | 136 | t.assert.throws(() => { |
128 | 137 | backup(database, 'hello.db', { |
129 | 138 | progress: 'invalid' |
|