Repository navigation
Description
SEVERITY: MEDIUM
Summary
When a Parse declares zero parameter types, which asyncpg and node-postgres do, parseCommand() recovers
the count by scanning the raw query text for $N with a regular expression and declares that many
varchar parameters. The scan does not respect string literals, dollar-quoted bodies or comments, so a
literal containing a dollar sign followed by digits is counted. The clients this fallback exists for
are exactly the ones that read ParameterDescription and validate the caller's argument count against
it, so they refuse a statement that needs no arguments.
Where (HEAD 21d2a0e)
- postgresw/src/main/java/com/arcadedb/postgres/PostgresNetworkExecutor.java:4692, detectParameterPlaceholders(), the regular expression scan over the raw text
- postgresw/src/main/java/com/arcadedb/postgres/PostgresNetworkExecutor.java:3407, its only call site, the paramCount == 0 arm, whose comment names asyncpg and node-postgres
- postgresw/src/main/java/com/arcadedb/postgres/PostgresNetworkExecutor.java:4672, writeParameterDescription()
Repro
A Parse declaring zero parameter types for a statement with no parameters and one literal. The text is
"SELECT 'price is $1 today' AS v".
PROBE 3: $N inside a string literal, Parse declaring 0 parameter types
### Parse(0 declared types) + Describe(S) -> [1, t, T, Z]
t count=1 oids=[1043]
T fields=1 [v tbl=0 attnum=0 oid=1043 len=-1 mod=-1 fmt=0]
-- real PostgreSQL: ParameterDescription count=0 --
### Bind(0 values) + Execute -> [2, D, C, Z]
D 'price is $1 today'
C tag=SELECT 1
The row is correct; the parameter count the client was told is not.
Refutation attempted
Does it break execution? Not on its own: the literal is untouched and the right row comes back. The
damage is entirely in the metadata and lands on a client that trusts ParameterDescription. Hence MEDIUM.
Does the engine mistake the literal for a parameter too? No. BaseExpression resolves $N only for an
identifier, and this $1 is inside a string literal, so it is never a candidate. The defect is confined
to the protocol's own count.
Harmless because clients declaring no types also do not read the description? The call site's comment
names asyncpg, and asyncpg does read it and does validate argument count against it. Combined with the
missing Bind count check reported above, the two cancel for a client that ignores the description and
compound for one that honours it.
Suggested fix
Scan with the literal awareness the rest of the module already applies to query text, skipping
single-quoted literals, dollar-quoted bodies, double-quoted identifiers and comments, so only a $N
appearing as an expression is counted. PostgresQuotedIdentifierRewriter already walks the text with
literal awareness and is the natural place to borrow the scanner from.
The guarantee to ask for: the count recovered from the text equals the count the SQL parser would
report for the same text, so a $N inside any quoted construct is never counted. Tying the recovered
count to the parser rather than to a regular expression stops the next quoting form from reopening it.
Scope / confidence
Executed: probe 3, output verbatim. Read: detectParameterPlaceholders(), its single call site,
writeParameterDescription(), and BaseExpression's resolution to confirm the literal is not mistaken for
a parameter at execution. I did not run asyncpg; the asyncpg consequence is stated from its documented
argument validation and from the call site's own comment naming it, and is the one part of this finding
I did not execute.
Dedup
Checked 10870, 10721, 8573, 10695 (a statement whose text merely contains pg_catalog answered without
running, the same class of raw-text matching that ignores string literals, elsewhere), 10882 (the
pg_type element-join recogniser still matching raw query text, string literals included). 10882 is the
closest neighbour and is the same root cause in a different scanner; it is CLOSED and covered the
catalog recogniser, not the parameter scan. Worth naming 10882 in the issue as the sibling.
Activity
fix(#11145, #11146, #11051, #11029): labelpropagation seeds, personal…
lvca commentedon Nov 2, 2026
This was already fixed by #11123 (issue #11018): the parameter count is now read the way the SQL parser reads the text, so a
$Ninside a string literal, a quoted identifier or a comment is no longer counted.SELECT 'price is $1 today' AS vnow describes 0 parameters. #11148 adds a regression test for exactly this case. Available from 26.11.1.❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.
fix(#11145, #11146, #11051, #11029): labelpropagation seeds, personal…