Skip to content

sqlite: fix abort on oversized SQL text - #67768

Open
christianaurichzm wants to merge 1 commit into
nodejs:mainfrom
christianaurichzm:sqlite-oversized-sql-text
Open

christianaurichzm wants to merge 1 commit into
nodejs:mainfrom
christianaurichzm:sqlite-oversized-sql-text

Conversation

@christianaurichzm

Copy link
Copy Markdown
Member

expandedSQL, sourceSQL, result column names and the sqlite.db.query trace callback abort the process on SQL text longer than String::kMaxLength in UTF-8:

$ node -e "const { Database } = require('node:sqlite'); const s = new Database(':memory:').prepare('SELECT ?'); s.run(Buffer.alloc(2 ** 28)); s.expandedSQL"

#
# Fatal error
# Check failed: String::kMaxLength >= len.

With a sqlite.db.query subscriber, run() alone aborts too.

These call sites pass the text to String::NewFromUtf8() without a length, and V8 then aborts instead of returning an empty handle. This routes the getters and column names through the helpers that column values already use, so they throw ERR_STRING_TOO_LONG. The trace callback passes the length and skips the event on an empty handle.

This picks up #66498 by @lazerg.

Fixes: #66487
Refs: #66498

`expandedSQL`, `sourceSQL`, column names and the `sqlite.db.query`
trace callback passed SQL text to `String::NewFromUtf8()` without a
length, and V8 aborted on text longer than `String::kMaxLength`.
Pass the length instead. The getters and column names now throw
`ERR_STRING_TOO_LONG`, and the trace callback skips the event so the
statement still runs.

Co-authored-by: lazerg <lazerg2@gmail.com>
Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/sqlite

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem. labels Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite: expandedSQL, sourceSQL, column names, and sqlite.db.query tracing abort the process on text longer than String::kMaxLength

2 participants