Fix crash in PREPARE with property parameter when enable_containment is off#2339
Merged
jrgemignani merged 2 commits intoapache:masterfrom Mar 3, 2026
Merged
Conversation
jrgemignani
approved these changes
Feb 27, 2026
There was a problem hiding this comment.
Pull request overview
Fixes a server crash in the Cypher MATCH property-constraints transformation when PREPARE is used with a property parameter ($props) while age.enable_containment = off, and adds regression coverage for the reported crash scenario.
Changes:
- Add a
cypher_paramtype check increate_property_constraints()to avoid incorrectly treating runtime parameters as parse-time maps. - Guard
keep_nullwrites intransform_match_entities()socypher_paramnodes aren’t corrupted bycypher_mapcasts. - Add regression tests and expected output for
PREPARE/EXECUTEwith vertex/edge property parameters under both containment modes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/backend/parser/cypher_clause.c |
Prevents invalid casts/dereferences for $props when containment is disabled; avoids unsafe keep_null writes. |
regress/sql/cypher_match.sql |
Adds regression SQL reproducing Issue #1964 for vertex and edge property parameters with PREPARE. |
regress/expected/cypher_match.out |
Updates expected output to match new regression coverage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…is off When age.enable_containment is set to off, executing a PREPARE statement with a property parameter (e.g., MATCH (n $props) RETURN n) causes a segfault. The crash occurs in transform_map_to_ind_recursive because the property_constraints node is a cypher_param, not a cypher_map, but is blindly cast to cypher_map and its keyvals field is dereferenced. Three fixes: - In create_property_constraints, when enable_containment is off and the constraint is a cypher_param, fall back to the containment operator (@>) since map decomposition requires known keys at parse time. - In transform_match_entities, guard the keep_null assignment for both vertex and edge property constraints with is_ag_node checks to avoid writing to the wrong struct layout. Fixes apache#1964 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When MATCH uses the =properties form (e.g., MATCH (n = $props)), the enable_containment=on path correctly uses @>> (top-level containment). The parameter fallback path unconditionally used @> (deep containment), ignoring the use_equals flag. Fix the fallback to mirror the enable_containment path by selecting @>> when use_equals is set. Add regression tests for =properties form with PREPARE for both vertices and edges, with enable_containment on and off. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c4ce7fc to
3aeabdc
Compare
jrgemignani
approved these changes
Mar 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PREPAREwith a property parameter ($props) whileage.enable_containmentis set tooffcreate_property_constraintsblindly castscypher_paramnodes tocypher_map*in the non-containment code path, then dereferences thekeyvalsfield which maps to thenamechar pointer ofcypher_param— reading invalid memorykeep_nullwrites oncypher_paramnodes intransform_match_entitiesfor both vertex and edge property constraintsReproducer
GDB backtrace
The crash occurs because
mapis actually acypher_paramnode ({extensible, name, location}), not acypher_map({extensible, keyvals, location, keep_null}). Thenamechar pointer is reinterpreted as thekeyvalsList pointer, and dereferencing it askeyvals->elements[i].ptr_valueaccesses invalid memory.Root cause analysis
When
age.enable_containment = on(the default),create_property_constraintshandles property parameters correctly:transform_cypher_expr()dispatchescypher_paramtotransform_cypher_param(), producing aFuncExprthat resolves the parameter at execution time@>containment operator:properties @> $propsWhen
age.enable_containment = off, the code takes theelsebranch (line 4246) which callstransform_map_to_ind(). This function is designed to decompose a knowncypher_map({key1: val1, key2: val2}) into individual index-based equality expressions (properties->"key1" = val1 AND properties->"key2" = val2). It cannot work with acypher_parambecause the map keys are not known until execution time.Additionally,
transform_match_entitieswriteskeep_null = trueby castingnode->props/rel->propstocypher_map*(lines 4677 and 4806 on master) without checking the actual node type, corrupting thecypher_paramstruct.Fix
Three changes in
cypher_clause.c:create_property_constraints: Before thecypher_mapcast, checkis_ag_node(property_constraints, cypher_param). For parameters, fall back to the containment operator (@>), which correctly resolves at execution time. This matches the behavior of theenable_containment = onpath.transform_match_entities(vertex): Guard thekeep_nullassignment withis_ag_node(node->props, cypher_map)to prevent writing to wrong struct memory.transform_match_entities(edge): Same guard foris_ag_node(rel->props, cypher_map).Test plan
PREPARE/EXECUTEwith vertex and edge property parameters, bothenable_containment = onandoffFixes #1964
AI Disclosure
AI tools (Claude by Anthropic) were used to assist in developing this fix, including root cause analysis, code changes, and regression tests.