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

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.54%. Comparing base (b4e974c) to head (f25ae20).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite.cc 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #67768   +/-   ##
=======================================
  Coverage   90.54%   90.54%           
=======================================
  Files         803      803           
  Lines      285293   285307   +14     
  Branches    55069    55074    +5     
=======================================
+ Hits       258311   258335   +24     
+ Misses      17102    17099    -3     
+ Partials     9880     9873    -7     
Files with missing lines Coverage Δ
src/node_sqlite.cc 83.08% <91.66%> (+0.04%) ⬆️

... and 32 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.

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