mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
sqlite: throw on oversized string values
SQLite serves TEXT up to SQLITE_MAX_LENGTH, past what V8 can represent as a string. V8 returns an empty handle without throwing, and the user-defined function path then suppressed the SQLite error as if a JavaScript exception were pending. exec() reported success for a statement that never ran, and get() returned undefined. Throw ERR_STRING_TOO_LONG when the value cannot be converted, and suppress a SQLite error only when an exception is actually pending. Assisted-by: Claude Code Signed-off-by: Guilherme Araújo <arauujogui@gmail.com> PR-URL: https://github.com/nodejs/node/pull/66209 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
1 parent
1f26576a3f
commit
c5b7a06d9b
2 files changed
+41
-2
No files matched your search
+12
-1
@@ -73,6 +73,13 @@ using v8::Value;
|
||||
|
||||
inline MaybeLocal<String> Utf8StringMaybeOneByte(Isolate* isolate,
|
||||
std::string_view input) {
|
||||
// SQLITE_MAX_LENGTH exceeds String::kMaxLength, and V8 returns an empty
|
||||
// handle without throwing. Raise the error here or the value is dropped.
|
||||
if (input.size() > static_cast<size_t>(String::kMaxLength)) [[unlikely]] {
|
||||
isolate->ThrowException(node::ERR_STRING_TOO_LONG(isolate));
|
||||
return MaybeLocal<String>();
|
||||
}
|
||||
|
||||
const int len = static_cast<int>(input.size());
|
||||
if (simdutf::validate_ascii(input.data(), input.size())) {
|
||||
return String::NewFromOneByte(
|
||||
@@ -351,7 +358,11 @@ class Database;
|
||||
inline void THROW_ERR_SQLITE_ERROR(Isolate* isolate, Database* db) {
|
||||
if (db->ShouldIgnoreSQLiteError()) {
|
||||
db->SetIgnoreNextSQLiteError(false);
|
||||
return;
|
||||
// Suppression that swallows no pending exception would also swallow the
|
||||
// SQLite error, reporting a failed statement as a success.
|
||||
if (isolate->HasPendingException()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Local<Object> e;
|
||||
|
||||
Reference in new issue
Block a user