Skip to content

Commit 44041d6

Browse files
committed
review fixed
1 parent a45872b commit 44041d6

File tree

3 files changed

+36
-115
lines changed

3 files changed

+36
-115
lines changed

doc/api/sqlite.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,30 +158,20 @@ changes:
158158
* `limits` {Object} Configuration for various SQLite limits. These limits
159159
can be used to prevent excessive resource consumption when handling
160160
potentially malicious input. See [Run-Time Limits][] and [Limit Constants][]
161-
in the SQLite documentation for details. The following properties are
162-
supported:
161+
in the SQLite documentation for details. Default values are determined by
162+
SQLite's compile-time defaults and may vary depending on how SQLite was
163+
built. The following properties are supported:
163164
* `length` {number} Maximum length of a string or BLOB.
164-
**Default:** `1000000000`.
165165
* `sqlLength` {number} Maximum length of an SQL statement.
166-
**Default:** `1000000000`.
167166
* `column` {number} Maximum number of columns.
168-
**Default:** `2000`.
169167
* `exprDepth` {number} Maximum depth of expression tree.
170-
**Default:** `1000`.
171168
* `compoundSelect` {number} Maximum number of terms in compound SELECT.
172-
**Default:** `500`.
173169
* `vdbeOp` {number} Maximum number of VDBE instructions.
174-
**Default:** `250000000`.
175170
* `functionArg` {number} Maximum number of function arguments.
176-
**Default:** `1000`.
177171
* `attach` {number} Maximum number of attached databases.
178-
**Default:** `10`.
179172
* `likePatternLength` {number} Maximum length of LIKE pattern.
180-
**Default:** `50000`.
181173
* `variableNumber` {number} Maximum number of SQL variables.
182-
**Default:** `32766`.
183174
* `triggerDepth` {number} Maximum trigger recursion depth.
184-
**Default:** `1000`.
185175

186176
Constructs a new `DatabaseSync` instance.
187177

src/node_sqlite.cc

Lines changed: 12 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -140,65 +140,23 @@ Local<DictionaryTemplate> getLazyIterTemplate(Environment* env) {
140140
} // namespace
141141

142142
// Mapping from JavaScript property names to SQLite limit constants
143-
// Default compile-time maximums from SQLite (these match SQLite's defaults)
144-
#ifndef SQLITE_MAX_LENGTH
145-
#define SQLITE_MAX_LENGTH 1000000000
146-
#endif
147-
#ifndef SQLITE_MAX_SQL_LENGTH
148-
#define SQLITE_MAX_SQL_LENGTH 1000000000
149-
#endif
150-
#ifndef SQLITE_MAX_COLUMN
151-
#define SQLITE_MAX_COLUMN 2000
152-
#endif
153-
#ifndef SQLITE_MAX_EXPR_DEPTH
154-
#define SQLITE_MAX_EXPR_DEPTH 1000
155-
#endif
156-
#ifndef SQLITE_MAX_COMPOUND_SELECT
157-
#define SQLITE_MAX_COMPOUND_SELECT 500
158-
#endif
159-
#ifndef SQLITE_MAX_VDBE_OP
160-
#define SQLITE_MAX_VDBE_OP 250000000
161-
#endif
162-
#ifndef SQLITE_MAX_FUNCTION_ARG
163-
#define SQLITE_MAX_FUNCTION_ARG 1000
164-
#endif
165-
#ifndef SQLITE_MAX_ATTACHED
166-
#define SQLITE_MAX_ATTACHED 10
167-
#endif
168-
#ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH
169-
#define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000
170-
#endif
171-
#ifndef SQLITE_MAX_VARIABLE_NUMBER
172-
#define SQLITE_MAX_VARIABLE_NUMBER 32766
173-
#endif
174-
#ifndef SQLITE_MAX_TRIGGER_DEPTH
175-
#define SQLITE_MAX_TRIGGER_DEPTH 1000
176-
#endif
177-
178143
struct LimitInfo {
179144
std::string_view js_name;
180145
int sqlite_limit_id;
181-
int max_value;
182146
};
183147

184148
static constexpr std::array<LimitInfo, 11> kLimitMapping = {{
185-
{"length", SQLITE_LIMIT_LENGTH, SQLITE_MAX_LENGTH},
186-
{"sqlLength", SQLITE_LIMIT_SQL_LENGTH, SQLITE_MAX_SQL_LENGTH},
187-
{"column", SQLITE_LIMIT_COLUMN, SQLITE_MAX_COLUMN},
188-
{"exprDepth", SQLITE_LIMIT_EXPR_DEPTH, SQLITE_MAX_EXPR_DEPTH},
189-
{"compoundSelect",
190-
SQLITE_LIMIT_COMPOUND_SELECT,
191-
SQLITE_MAX_COMPOUND_SELECT},
192-
{"vdbeOp", SQLITE_LIMIT_VDBE_OP, SQLITE_MAX_VDBE_OP},
193-
{"functionArg", SQLITE_LIMIT_FUNCTION_ARG, SQLITE_MAX_FUNCTION_ARG},
194-
{"attach", SQLITE_LIMIT_ATTACHED, SQLITE_MAX_ATTACHED},
195-
{"likePatternLength",
196-
SQLITE_LIMIT_LIKE_PATTERN_LENGTH,
197-
SQLITE_MAX_LIKE_PATTERN_LENGTH},
198-
{"variableNumber",
199-
SQLITE_LIMIT_VARIABLE_NUMBER,
200-
SQLITE_MAX_VARIABLE_NUMBER},
201-
{"triggerDepth", SQLITE_LIMIT_TRIGGER_DEPTH, SQLITE_MAX_TRIGGER_DEPTH},
149+
{"length", SQLITE_LIMIT_LENGTH},
150+
{"sqlLength", SQLITE_LIMIT_SQL_LENGTH},
151+
{"column", SQLITE_LIMIT_COLUMN},
152+
{"exprDepth", SQLITE_LIMIT_EXPR_DEPTH},
153+
{"compoundSelect", SQLITE_LIMIT_COMPOUND_SELECT},
154+
{"vdbeOp", SQLITE_LIMIT_VDBE_OP},
155+
{"functionArg", SQLITE_LIMIT_FUNCTION_ARG},
156+
{"attach", SQLITE_LIMIT_ATTACHED},
157+
{"likePatternLength", SQLITE_LIMIT_LIKE_PATTERN_LENGTH},
158+
{"variableNumber", SQLITE_LIMIT_VARIABLE_NUMBER},
159+
{"triggerDepth", SQLITE_LIMIT_TRIGGER_DEPTH},
202160
}};
203161

204162
// Helper function to find limit info from JS property name
@@ -387,7 +345,7 @@ class CustomAggregate {
387345
static inline void xStepBase(sqlite3_context* ctx,
388346
int argc,
389347
sqlite3_value** argv,
390-
Global<Function> CustomAggregate::*mptr) {
348+
Global<Function> CustomAggregate::* mptr) {
391349
CustomAggregate* self =
392350
static_cast<CustomAggregate*>(sqlite3_user_data(ctx));
393351
Environment* env = self->env_;
@@ -848,13 +806,6 @@ Intercepted DatabaseSyncLimits::LimitsSetter(
848806
return Intercepted::kYes;
849807
}
850808

851-
// Validate against compile-time maximum
852-
if (new_value > limit_info->max_value) {
853-
THROW_ERR_OUT_OF_RANGE(isolate,
854-
"Limit value exceeds compile-time maximum.");
855-
return Intercepted::kYes;
856-
}
857-
858809
sqlite3_limit(
859810
limits->database_->Connection(), limit_info->sqlite_limit_id, new_value);
860811
return Intercepted::kYes;
@@ -1390,14 +1341,6 @@ void DatabaseSync::New(const FunctionCallbackInfo<Value>& args) {
13901341
return;
13911342
}
13921343

1393-
if (limit_val > kLimitMapping[i].max_value) {
1394-
std::string msg = "The \"options.limits." +
1395-
std::string(kLimitMapping[i].js_name) +
1396-
"\" argument exceeds compile-time maximum.";
1397-
THROW_ERR_OUT_OF_RANGE(env->isolate(), msg);
1398-
return;
1399-
}
1400-
14011344
open_config.set_initial_limit(kLimitMapping[i].sqlite_limit_id,
14021345
limit_val);
14031346
}

test/parallel/test-sqlite-limits.js

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,28 @@ const { DatabaseSync } = require('node:sqlite');
55
const { suite, test } = require('node:test');
66

77
suite('DatabaseSync limits', () => {
8-
test('default limits match expected SQLite defaults', (t) => {
8+
test('limits object has expected properties with positive values', (t) => {
99
const db = new DatabaseSync(':memory:');
10-
t.assert.deepStrictEqual({ ...db.limits }, {
11-
length: 1000000000,
12-
sqlLength: 1000000000,
13-
column: 2000,
14-
exprDepth: 1000,
15-
compoundSelect: 500,
16-
vdbeOp: 250000000,
17-
functionArg: 1000,
18-
attach: 10,
19-
likePatternLength: 50000,
20-
variableNumber: 32766,
21-
triggerDepth: 1000,
22-
});
10+
const expectedProperties = [
11+
'length',
12+
'sqlLength',
13+
'column',
14+
'exprDepth',
15+
'compoundSelect',
16+
'vdbeOp',
17+
'functionArg',
18+
'attach',
19+
'likePatternLength',
20+
'variableNumber',
21+
'triggerDepth',
22+
];
23+
24+
for (const prop of expectedProperties) {
25+
t.assert.strictEqual(typeof db.limits[prop], 'number',
26+
`${prop} should be a number`);
27+
t.assert.ok(db.limits[prop] > 0,
28+
`${prop} should be positive`);
29+
}
2330
});
2431

2532
test('constructor accepts limits option', (t) => {
@@ -158,25 +165,6 @@ suite('DatabaseSync limits', () => {
158165
});
159166
});
160167

161-
test('throws on value exceeding compile-time maximum via setter', (t) => {
162-
const db = new DatabaseSync(':memory:');
163-
t.assert.throws(() => {
164-
db.limits.attach = 100;
165-
}, {
166-
name: 'RangeError',
167-
message: /Limit value exceeds compile-time maximum/,
168-
});
169-
});
170-
171-
test('throws on value exceeding compile-time maximum in constructor', (t) => {
172-
t.assert.throws(() => {
173-
new DatabaseSync(':memory:', { limits: { attach: 100 } });
174-
}, {
175-
name: 'RangeError',
176-
message: /options\.limits\.attach.*exceeds compile-time maximum/,
177-
});
178-
});
179-
180168
test('partial limits in constructor', (t) => {
181169
const db = new DatabaseSync(':memory:', {
182170
limits: {

0 commit comments

Comments
 (0)