sqlite: use 64-bit result APIs for UDF return values

JSValueToSQLiteResult() passed the size_t length of returned
ArrayBuffers and ArrayBufferViews to sqlite3_result_blob(), which
takes an int. Buffers larger than INT_MAX bytes were narrowed,
yielding silently truncated blobs or bogus empty text values.

Use sqlite3_result_blob64() and sqlite3_result_text64(), matching
Statement::BindValue(), so oversized values are rejected with
SQLITE_TOOBIG.

Assisted-by: Claude Code
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67089
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
Guilherme Araújo authored and GitHub committed 2026-11-06 11:53:45 +00:00
1 parent 280798a30d
commit 128f247ea4
2 files changed
+26 -3

No files matched your search

+3 -2
View File
@@ -332,11 +332,12 @@ void JSValueToSQLiteResult(Isolate* isolate,
sqlite3_result_double(ctx, value.As<Number>()->Value());
} else if (value->IsString()) {
Utf8Value val(isolate, value.As<String>());
sqlite3_result_text(ctx, *val, val.length(), SQLITE_TRANSIENT);
sqlite3_result_text64(
ctx, *val, val.length(), SQLITE_TRANSIENT, SQLITE_UTF8);
} else if (value->IsArrayBufferView() || value->IsArrayBuffer() ||
value->IsSharedArrayBuffer()) {
ArrayBufferViewContents<uint8_t> buf(value);
sqlite3_result_blob(ctx, buf.data(), buf.length(), SQLITE_TRANSIENT);
sqlite3_result_blob64(ctx, buf.data(), buf.length(), SQLITE_TRANSIENT);
} else if (value->IsBigInt()) {
bool lossless;
int64_t as_int = value.As<BigInt>()->Int64Value(&lossless);