Repository navigation
fix(#5884,#5885): validate argument count for SQL functions and methods before execution - #5969
Conversation
…efore execution Both FunctionCall and MethodCall (the SQL parser's dispatch points for function()/.method() calls) now call the existing checkArity() contract before invoking a function or method, so a wrong argument count is reported as a CommandSemanticException (HTTP 400) instead of whatever raw JDK exception (ArrayIndexOutOfBoundsException, NullPointerException, ClassCastException, NegativeArraySizeException) the unguarded execute() happened to throw. The aggregate-projection dispatch path (FunctionAggregationContext, used for aggregate functions and any function projected with no FROM) gets the same check, since it is a second entry point functions can be reached through. The 43 functions and 19 methods listed in the two issues now declare correct getMinArgs()/getMaxArgs() (functions) or minParams/maxParams (methods) bounds; most methods already stored the right numbers but had no runtime enforcement. Fixing the enforcement surfaced a few more pre-existing bound mismatches (ifnull, sort, transform, toUpperCase, toLowerCase) that were silently tolerating a wrong argument count. bothE/bothV/inE/inV/outE/outV take zero required arguments, so the NullPointerException they threw was not an arity bug: SQLFunctionMove's v2e()/e2v() dereferenced a null receiver unconditionally, unlike v2v() which already null-checked. Both now match v2v(). Negative-value range guards (a different class of bug: the argument count is right, the value is not) were added to left(), right() and charat(), which clamp/null out-of-range input the way MySQL's LEFT/RIGHT do instead of throwing StringIndexOutOfBoundsException.
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
🟢 Coverage 100.00% diff coverage
Metric Results Coverage variation Report missing for afeb0dd1 Diff coverage ✅ 100.00% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (afeb0dd) Report Missing Report Missing Report Missing Head commit (8c4eb4a) 185802 131136 70.58% Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#5969) 81 81 100.00% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
ReviewSolid, well-scoped chokepoint fix. Reviewed the diff in full (all 48 changed files) plus the surrounding context for each touched What's good
Things worth a look (none blocking, in my read)
Security / performanceNo concerns. The added checks are O(1) comparisons on already-computed argument arrays/counts, done once per call (or once per statement for the aggregation path) rather than per row, so no measurable overhead. No new dependencies, no new surface for injection or resource exhaustion - if anything this closes off a minor information-disclosure vector (malformed queries previously could surface raw JDK exceptions with internal stack details rather than a clean validation error). Test coverageGood. Both regression tests are parameterized off the actual affected-function/method lists from the two issues, check both "too few" and (for methods) "too many" arguments, and include targeted tests for the negative-value clamping behavior. The |
…t() receiver Two follow-ups from code review on PR #5969: - FunctionAggregationContext's new checkArity() call was only exercised by the no-FROM synthetic-aggregation cases in the existing tests. Add a test that runs stddev()/count(*) through a real GROUP BY over actual records, so the true aggregation dispatch path is covered too. - SQLMethodCharAt.execute() gained a value == null guard alongside the existing params[0] == null one; the only existing test exercised both as null together. Add a case that isolates a null receiver with a non-null index, which used to throw NullPointerException on value.toString() before this guard existed.
ReviewWent through this in detail — the chokepoint approach (enforcing at the two SQL-parser dispatch points plus the aggregate-projection path, rather than 62 hand-written guards) is the right shape for this fix, and it reuses the existing Correctness checks performed (I couldn't run
Minor observations, non-blocking:
No security or dependency concerns — this only tightens input validation, and there's no new dependency. Test coverage is solid: both regression test classes are driven off the declared bounds themselves rather than hardcoded per-function counts, so a future regression in the declaration (not just the enforcement) will also be caught. Nice fix overall — the "chokepoint, not 62 guards" framing holds up under inspection. |
…hod-call path Second code-review pass on PR #5969 pointed out that MethodCall's isGraphFunction() branch (the <expr>.out()/.in()/.both()/... method-call syntax, as opposed to the out()/in()/both() function-call syntax the existing tests exercise) also gained a checkArity() call, but nothing drove a query through it. Add a minimal traversal to confirm it still works with correct arguments.
ReviewThis is a well-scoped chokepoint fix: routing both SQL-parser dispatch points ( The Minor/non-blocking observations
Test coverageSolid - Overall: solid, well-tested fix. The three points above are minor and none are blocking. |
…le count(*) doc Third code-review pass on PR #5969: - FunctionCall.execute() and MethodCall.execute()'s isGraphFunction() branch each called paramValues.toArray() once for checkArity() and again inside whichever execute() branch fired. Compute it once and reuse it, matching the pattern MethodCall's SQLMethod branch already used. - MethodCall's isGraphFunction() branch now guards against a null function lookup before calling checkArity() on it, matching FunctionCall's existing null check instead of relying on execute() to NPE a few lines later. - SQLFunctionCount.getMinArgs()'s comment claimed count(*) carries no argument at all; FunctionCall.isStar() actually requires a single synthetic argument to recognize the star form. Left uncorrected, a future edit trusting that comment could tighten the bound and break count(*) through the aggregate-projection path this PR now enforces checkArity on unconditionally.
ReviewSolid, well-scoped fix. I traced the dispatch chokepoints ( Correctness
Minor / non-blocking
Test coverage
Security / performanceNo concerns. The added checks are O(1) integer comparisons on paths that already allocate the params array; no new dependencies. Arity failures now consistently surface as Nothing blocking from my pass - a nice chokepoint-level fix rather than 62 scattered guards, and the description accurately reflects the diff. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5969 +/- ##
==========================================
+ Coverage 68.18% 68.24% +0.06%
==========================================
Files 1797 1797
Lines 153223 153459 +236
Branches 32448 32479 +31
==========================================
+ Hits 104477 104733 +256
+ Misses 35341 35320 -21
- Partials 13405 13406 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Brings the fork up to 26.9.1-SNAPSHOT, which carries the August fixes we filed: ArcadeData#5711 (HTTP row truncation), ArcadeData#5745/ArcadeData#5788 (GAV), ArcadeData#5746 (Cypher through GAVFusedChain), ArcadeData#5747 (close-time HNSW rebuild, our PR ArcadeData#5787), ArcadeData#5796 (Redis port), ArcadeData#5824 (@Rid IN replanned as FETCH FROM RIDs). All verified against the shipped jars before this merge. Conflicts resolved: - 15 .github files kept deleted. Upstream CI the fork does not run; we carry only the five Python workflows. - test-python-examples.yml took upstream's two dependabot SHA bumps (setup-java v5.6.0 -> v5.7.0, cache v4.3.0 -> v6.1.0), staying aligned with the SHA-pinning their review requires. - test_server_wire_protocols.py kept ours. Upstream carries the version from PR ArcadeData#5807, which still has the redis xfail; ArcadeData#5796 is fixed and the marker was retired in a5d82c0. Behaviour changes to watch, none of which renamed or removed a JPype-facing API: ArcadeData#5969 now validates SQL function and method arity, ArcadeData#5908 makes sum/avg reject non-numeric input, ArcadeData#5983 bounds regex backtracking, and ArcadeData#5786 caps vector.neighbors groupBy output per index. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0173qFfapQBiGxaV7apSZ4X8
Summary
Fixes #5884 and #5885: 43 SQL functions and 19 SQL methods answered a call with too few arguments with a raw JDK exception (
ArrayIndexOutOfBoundsException,NullPointerException,ClassCastException,NegativeArraySizeException) instead of a validation error.The infrastructure for this already existed (
Function.checkArity()/FunctionArity, added for #5484/#5602/#5627) but was never invoked from the SQL-parser dispatch points these two issues cover. This is a chokepoint fix rather than 62 separate hand-written guards:FunctionCall.execute()andMethodCall.execute()(the two SQL-parser dispatch points forfunction()/.method()calls) now callcheckArity()before invoking the function/method.FunctionAggregationContext(a second, less obvious dispatch path used both for real aggregate functions and for any function projected with noFROMclause) gets the same check, once per statement rather than per row.SQLMethodgained the samegetMinParams()/getMaxParams()/checkArity()contractFunctionalready had;AbstractSQLMethodalready stored the rightminParams/maxParamsfor almost every method, they just weren't enforced.A wrong argument count is now a
CommandSemanticException(HTTP 400), matching how it already worked for the functions that got this right (bellmanFord(),circle(),vector.fuse()).Two sub-cases handled differently
getMinArgs()/getMaxArgs()(functions) or constructor bounds (methods) and wiring the enforcement described above.bothE/bothV/inE/inV/outE/outVlegitimately take zero required arguments (labels are optional). TheirNullPointerExceptioncame fromSQLFunctionMove.v2e()/e2v()dereferencing a null receiver unconditionally, unlikev2v()which already null-checks. Fixed to matchv2v().left(),right(),charat()had the right argument count but no guard on the value. They now clamp/return-null for out-of-range input the way MySQL'sLEFT/RIGHTdo, instead of throwingStringIndexOutOfBoundsException.substring(),indexof(),lastindexof()turned out to already tolerate negative values safely on inspection - verified rather than "fixed" a second time.Fallout from turning on enforcement
Running the full test suite after wiring the checks surfaced a handful of other pre-existing methods whose declared
minParams/maxParamsdidn't match what theirexecute()actually needed/tolerated - previously invisible because nothing enforced the declaration. Fixed the same way:ifnull(method),sort,transform,toUpperCase,toLowerCase.Test plan
FunctionArgumentValidationRegressionTest- sweeps all 43 listed functions, driven off each function's own declaredgetMinArgs()/getMaxArgs(), asserting too-few-arguments raisesCommandSemanticException(not a raw exception), and that the six zero-arg graph functions tolerate a missing receiver gracefully.MethodArgumentValidationRegressionTest- same sweep for all 19 listed methods (too few / too many args), plus dedicated negative-value tests forleft(),right(),charat().enginemodule test suite: 10,963 tests / 1,314 classes, 0 failures, 0 errors.🤖 Generated with Claude Code
https://claude.ai/code/session_01X1y2csftaVgtrNwgSNETzL