Skip to content

sqlite: fix abort on oversized SQL text - #67768

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
christianaurichzm:sqlite-oversized-sql-text
Nov 27, 2026
Merged

nodejs-github-bot merged 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

@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
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.51%. Comparing base (b4e974c) to head (cd2ad81).
⚠️ Report is 49 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite.cc 81.81% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67768      +/-   ##
==========================================
- Coverage   90.54%   90.51%   -0.03%     
==========================================
  Files         803      805       +2     
  Lines      285293   285821     +528     
  Branches    55069    55196     +127     
==========================================
+ Hits       258311   258712     +401     
- Misses      17102    17199      +97     
- Partials     9880     9910      +30     
Files with missing lines Coverage Δ
src/node_sqlite.cc 82.91% <81.81%> (-0.13%) ⬇️

... and 61 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/node_sqlite.cc Outdated
Isolate* isolate = env->isolate();
HandleScope handle_scope(isolate);

// With an explicit length, V8 returns an empty handle instead of aborting

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: comments are a bit wordy, we can trim them.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, trimmed both.

`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>
@christianaurichzm christianaurichzm added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Nov 26, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 26, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@christianaurichzm christianaurichzm added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 27, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 2fdac69 into nodejs:main Nov 27, 2026
77 of 78 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 2fdac69

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 27, 2026
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
`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>
PR-URL: nodejs#67768
Fixes: nodejs#66487
Refs: nodejs#66498
Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. 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

4 participants