-
-
Notifications
You must be signed in to change notification settings - Fork 35.8k
sqlite: validate maxSize argument in createTagStore() #63792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1044,10 +1044,20 @@ 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]->IsInt32()) { | ||||||
| THROW_ERR_INVALID_ARG_TYPE( | ||||||
| env->isolate(), "The \"maxSize\" argument must be an integer."); | ||||||
| return; | ||||||
| } | ||||||
| capacity = args[0].As<Int32>()->Value(); | ||||||
| if (capacity < 0) { | ||||||
| THROW_ERR_OUT_OF_RANGE( | ||||||
| env->isolate(), | ||||||
| "The \"maxSize\" argument must be a non-negative integer."); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we accept
Suggested change
|
||||||
| return; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| BaseObjectPtr<SQLTagStore> session = | ||||||
| SQLTagStore::Create(env, BaseObjectWeakPtr<DatabaseSync>(db), capacity); | ||||||
| if (!session) { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,6 +112,30 @@ test('TagStore capacity, size, and clear', () => { | |
| assert.strictEqual(sql.capacity, 10); | ||
| }); | ||
|
|
||
| test('createTagStore throws on invalid maxSize', () => { | ||
| const db = new DatabaseSync(':memory:'); | ||
|
|
||
| assert.throws(() => db.createTagStore(-1), { | ||
| code: 'ERR_OUT_OF_RANGE', | ||
| message: /maxSize/, | ||
| }); | ||
|
|
||
| assert.throws(() => db.createTagStore(NaN), { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| message: /maxSize/, | ||
| }); | ||
|
|
||
| assert.throws(() => db.createTagStore(1.5), { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
|
Comment on lines
+124
to
+129
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should likely be |
||
| message: /maxSize/, | ||
| }); | ||
|
|
||
| assert.throws(() => db.createTagStore('abc'), { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| message: /maxSize/, | ||
| }); | ||
| }); | ||
|
|
||
| test('sql.db returns the associated DatabaseSync instance', () => { | ||
| assert.strictEqual(sql.db, db); | ||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user runs
database.createTagStore(Number.MAX_SAFE_INTEGER), that error message is going to be confusing