Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4c181e2

Browse filesBrowse files
mertcanaltinaduh95
authored andcommitted
sqlite: add limits property to DatabaseSync
PR-URL: #61298 Fixes: #61268 Reviewed-By: René <contact.9a5d6388@renegade334.me.uk> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 940b58c commit 4c181e2
Copy full SHA for 4c181e2

5 files changed

+707Lines changed: 707 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/sqlite.md‎

Copy file name to clipboardExpand all lines: doc/api/sqlite.md
+49Lines changed: 49 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,23 @@ changes:
160160
language features that allow ordinary SQL to deliberately corrupt the database file are disabled.
161161
The defensive flag can also be set using `enableDefensive()`.
162162
**Default:** `true`.
163+
* `limits` {Object} Configuration for various SQLite limits. These limits
164+
can be used to prevent excessive resource consumption when handling
165+
potentially malicious input. See [Run-Time Limits][] and [Limit Constants][]
166+
in the SQLite documentation for details. Default values are determined by
167+
SQLite's compile-time defaults and may vary depending on how SQLite was
168+
built. The following properties are supported:
169+
* `length` {number} Maximum length of a string or BLOB.
170+
* `sqlLength` {number} Maximum length of an SQL statement.
171+
* `column` {number} Maximum number of columns.
172+
* `exprDepth` {number} Maximum depth of an expression tree.
173+
* `compoundSelect` {number} Maximum number of terms in a compound SELECT.
174+
* `vdbeOp` {number} Maximum number of VDBE instructions.
175+
* `functionArg` {number} Maximum number of function arguments.
176+
* `attach` {number} Maximum number of attached databases.
177+
* `likePatternLength` {number} Maximum length of a LIKE pattern.
178+
* `variableNumber` {number} Maximum number of SQL variables.
179+
* `triggerDepth` {number} Maximum trigger recursion depth.
163180

164181
Constructs a new `DatabaseSync` instance.
165182

@@ -447,6 +464,36 @@ added:
447464
* Type: {boolean} Whether the database is currently within a transaction. This method
448465
is a wrapper around [`sqlite3_get_autocommit()`][].
449466

467+
### `database.limits`
468+
469+
<!-- YAML
470+
added: REPLACEME
471+
-->
472+
473+
* Type: {Object}
474+
475+
An object for getting and setting SQLite database limits at runtime.
476+
Each property corresponds to an SQLite limit and can be read or written.
477+
478+
```js
479+
const db = new DatabaseSync(':memory:');
480+
481+
// Read current limit
482+
console.log(db.limits.length);
483+
484+
// Set a new limit
485+
db.limits.sqlLength = 100000;
486+
487+
// Reset a limit to its compile-time maximum
488+
db.limits.sqlLength = Infinity;
489+
```
490+
491+
Available properties: `length`, `sqlLength`, `column`, `exprDepth`,
492+
`compoundSelect`, `vdbeOp`, `functionArg`, `attach`, `likePatternLength`,
493+
`variableNumber`, `triggerDepth`.
494+
495+
Setting a property to `Infinity` resets the limit to its compile-time maximum value.
496+
450497
### `database.open()`
451498

452499
<!-- YAML
@@ -1472,6 +1519,8 @@ callback function to indicate what type of operation is being authorized.
14721519
[Changesets and Patchsets]: https://www.sqlite.org/sessionintro.html#changesets_and_patchsets
14731520
[Constants Passed To The Conflict Handler]: https://www.sqlite.org/session/c_changeset_conflict.html
14741521
[Constants Returned From The Conflict Handler]: https://www.sqlite.org/session/c_changeset_abort.html
1522+
[Limit Constants]: https://www.sqlite.org/c3ref/c_limit_attached.html
1523+
[Run-Time Limits]: https://www.sqlite.org/c3ref/limit.html
14751524
[SQL injection]: https://en.wikipedia.org/wiki/SQL_injection
14761525
[Type conversion between JavaScript and SQLite]: #type-conversion-between-javascript-and-sqlite
14771526
[`ATTACH DATABASE`]: https://www.sqlite.org/lang_attach.html
Collapse file

‎src/env_properties.h‎

Copy file name to clipboardExpand all lines: src/env_properties.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@
237237
V(kind_string, "kind") \
238238
V(last_insert_rowid_string, "lastInsertRowid") \
239239
V(length_string, "length") \
240+
V(limits_string, "limits") \
240241
V(library_string, "library") \
241242
V(loop_count, "loopCount") \
242243
V(max_buffer_string, "maxBuffer") \
@@ -435,6 +436,7 @@
435436
V(socketaddress_constructor_template, v8::FunctionTemplate) \
436437
V(space_stats_template, v8::DictionaryTemplate) \
437438
V(sqlite_column_template, v8::DictionaryTemplate) \
439+
V(sqlite_limits_template, v8::ObjectTemplate) \
438440
V(sqlite_run_result_template, v8::DictionaryTemplate) \
439441
V(sqlite_statement_sync_constructor_template, v8::FunctionTemplate) \
440442
V(sqlite_statement_sync_iterator_constructor_template, v8::FunctionTemplate) \

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.