sqlite: validate maxSize argument in createTagStore()#63792
sqlite: validate maxSize argument in createTagStore()#63792Anshikakalpana wants to merge 1 commit into
Conversation
|
Review requested:
|
68d5139 to
3c0477b
Compare
| if (capacity < 0) { | ||
| THROW_ERR_OUT_OF_RANGE( | ||
| env->isolate(), | ||
| "The \"maxSize\" argument must be a non-negative integer."); |
There was a problem hiding this comment.
If we accept 0, technically that's a negative number
| "The \"maxSize\" argument must be a non-negative integer."); | |
| "The \"maxSize\" argument must be a positive integer."); |
There was a problem hiding this comment.
Fixed — now using val <= 0 check, so 0 is also rejected with ERR_OUT_OF_RANGE.
| 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."); |
There was a problem hiding this comment.
If the user runs database.createTagStore(Number.MAX_SAFE_INTEGER), that error message is going to be confusing
There was a problem hiding this comment.
Fixed — replaced IsInt32() with IsNumber() + double range check. Now Number.MAX_SAFE_INTEGER correctly throws ERR_OUT_OF_RANGE.
| code: 'ERR_INVALID_ARG_TYPE', | ||
| message: /maxSize/, | ||
| }); | ||
|
|
||
| assert.throws(() => db.createTagStore(1.5), { | ||
| code: 'ERR_INVALID_ARG_TYPE', |
There was a problem hiding this comment.
This should likely be ERR_OUT_OF_RANGE, like e.g. node -e 'child_process.spawn("/dev/null", { uid: 1.3 })' does
There was a problem hiding this comment.
Fixed — floats now throw ERR_OUT_OF_RANGE instead of ERR_INVALID_ARG_TYPE.
Signed-off-by: anshikakalpana <anshikajain196872@gmail.com>
3c0477b to
406e215
Compare
Fixes: #63791
database.createTagStore()accepted invalid values for itsmaxSizeargument without throwing. Negative integers caused integer overflow, NaN and floats produced garbage capacity values, and strings were silently ignored.The
maxSizeparameter is documented as{integer}and represents a cache size, so negative values are meaningless.This PR adds validation to reject:
ERR_INVALID_ARG_TYPEERR_OUT_OF_RANGE