sqlite: validate maxSize argument in createTagStore()

Signed-off-by: anshikakalpana <anshikajain196872@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/63792
Fixes: https://github.com/nodejs/node/issues/63791
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anshika Jain authored and Antoine du Hamel committed 2026-08-27 14:00:31 +02:00
1 parent cd84d55c81
commit d6d2a71bee
2 files changed
+50 -3

No files matched your search

+16 -3
View File
@@ -1068,10 +1068,23 @@ void DatabaseSync::CreateTagStore(const FunctionCallbackInfo<Value>& args) {
return;
}
int capacity = 1000;
if (args.Length() > 0 && args[0]->IsNumber()) {
capacity = args[0].As<Number>()->Value();
if (args.Length() > 0 && !args[0]->IsUndefined()) {
if (!args[0]->IsNumber()) {
THROW_ERR_INVALID_ARG_TYPE(
env->isolate(),
"The \"maxSize\" argument must be a positive integer.");
return;
}
double val = args[0].As<Number>()->Value();
if (std::floor(val) != val || val <= 0 ||
val > std::numeric_limits<int>::max()) {
THROW_ERR_OUT_OF_RANGE(
env->isolate(),
"The \"maxSize\" argument must be a positive integer.");
return;
}
capacity = static_cast<int>(val);
}
BaseObjectPtr<SQLTagStore> session =
SQLTagStore::Create(env, BaseObjectWeakPtr<DatabaseSync>(db), capacity);
if (!session) {
+34
View File
@@ -257,6 +257,40 @@ test('a finished iterator stays done and does not restart', () => {
assert.strictEqual(iter.next().done, true);
});
test('createTagStore throws on invalid maxSize', () => {
const db = new DatabaseSync(':memory:');
assert.throws(() => db.createTagStore(0), {
code: 'ERR_OUT_OF_RANGE',
message: /maxSize/,
});
assert.throws(() => db.createTagStore(-1), {
code: 'ERR_OUT_OF_RANGE',
message: /maxSize/,
});
assert.throws(() => db.createTagStore(NaN), {
code: 'ERR_OUT_OF_RANGE',
message: /maxSize/,
});
assert.throws(() => db.createTagStore(1.5), {
code: 'ERR_OUT_OF_RANGE',
message: /maxSize/,
});
assert.throws(() => db.createTagStore('abc'), {
code: 'ERR_INVALID_ARG_TYPE',
message: /maxSize/,
});
assert.throws(() => db.createTagStore(Number.MAX_SAFE_INTEGER), {
code: 'ERR_OUT_OF_RANGE',
message: /maxSize/,
});
});
test('sql.db returns the associated DatabaseSync instance', () => {
assert.strictEqual(sql.db, db);
});