Skip to content

Server crashes when executing PREPARE property_ps(agtype)... #1964

Closed

Description

@saygoodbyye

Describe the bug
Server crashes when executing the following SQL-script

How are you accessing AGE (Command line, driver, etc.)?
Accessing AGE through command line.

What data setup do we need to do?
Apache AGE (PG16 branch) with PostgreSQL (REL_16_STABLE).

What is the necessary configuration info needed?
My PostgreSQL configuration:

./configure CFLAGS=" -Og" --enable-tap-tests --enable-debug --enable-cassert

What is the command that caused the error?

CREATE EXTENSION age;
SET search_path TO ag_catalog;
SET age.enable_containment = off;
SELECT create_graph('cypher_match');
PREPARE property_ps(agtype) AS SELECT * FROM cypher('cypher_match', $$MATCH (n $props) RETURN n $$, $1) AS (p agtype);

backtrace:

#0  0x00007bcf9cd92bd0 in transform_map_to_ind_recursive (cpstate=0x628fff633388, entity=0x628fff634698, map=0x628fff4d0548, parent_fields=parent_fields@entry=0x0) at src/backend/parser/cypher_clause.c:3894
#1  0x00007bcf9cd92cf7 in transform_map_to_ind (cpstate=cpstate@entry=0x628fff633388, entity=entity@entry=0x628fff634698, map=map@entry=0x628fff4d0548) at src/backend/parser/cypher_clause.c:3845
#2  0x00007bcf9cd92ee8 in create_property_constraints (cpstate=cpstate@entry=0x628fff633388, entity=entity@entry=0x628fff634698, property_constraints=0x628fff4d0548, prop_expr=0x628fff6347e8, prop_expr@entry=0x0)
    at src/backend/parser/cypher_clause.c:4087
#3  0x00007bcf9cd939c8 in transform_match_entities (cpstate=cpstate@entry=0x628fff633388, query=query@entry=0x628fff633598, path=path@entry=0x628fff4d05e0) at src/backend/parser/cypher_clause.c:4517
#4  0x00007bcf9cd94660 in transform_match_path (cpstate=cpstate@entry=0x628fff633388, query=query@entry=0x628fff633598, path=0x628fff4d05e0) at src/backend/parser/cypher_clause.c:4107
#5  0x00007bcf9cd94784 in transform_match_pattern (cpstate=cpstate@entry=0x628fff633388, query=query@entry=0x628fff633598, pattern=0x628fff4d0630, where=where@entry=0x0) at src/backend/parser/cypher_clause.c:3182
#6  0x00007bcf9cd97398 in transform_cypher_match_pattern (cpstate=cpstate@entry=0x628fff633388, clause=clause@entry=0x628fff633218) at src/backend/parser/cypher_clause.c:2771
#7  0x00007bcf9cd97462 in transform_cypher_match (cpstate=cpstate@entry=0x628fff633388, clause=clause@entry=0x628fff633218) at src/backend/parser/cypher_clause.c:2508
#8  0x00007bcf9cd999c5 in transform_cypher_clause (cpstate=cpstate@entry=0x628fff633388, clause=clause@entry=0x628fff633218) at src/backend/parser/cypher_clause.c:375
#9  0x00007bcf9cd96353 in analyze_cypher_clause (transform=0x7bcf9cd99816 <transform_cypher_clause>, clause=0x628fff633218, parent_cpstate=parent_cpstate@entry=0x628fff4cefe8) at src/backend/parser/cypher_clause.c:6401
#10 0x00007bcf9cd9659f in transform_cypher_clause_as_subquery (cpstate=cpstate@entry=0x628fff4cefe8, transform=transform@entry=0x7bcf9cd99816 <transform_cypher_clause>, clause=<optimized out>, alias=alias@entry=0x0,
    add_rte_to_query=add_rte_to_query@entry=true) at src/backend/parser/cypher_clause.c:6322
#11 0x00007bcf9cd96ab2 in transform_cypher_return (cpstate=cpstate@entry=0x628fff4cefe8, clause=clause@entry=0x628fff633248) at src/backend/parser/cypher_clause.c:2136
#12 0x00007bcf9cd9986d in transform_cypher_clause (cpstate=cpstate@entry=0x628fff4cefe8, clause=clause@entry=0x628fff633248) at src/backend/parser/cypher_clause.c:358
#13 0x00007bcf9cd8de58 in analyze_cypher (stmt=stmt@entry=0x628fff6331c8, parent_pstate=parent_pstate@entry=0x628fff4cfe48, query_str=query_str@entry=0x628fff4cf3e8 "MATCH (n $props) RETURN n ", query_loc=query_loc@entry=70,
    graph_name=graph_name@entry=0x628fff4cf348 "cypher_match", graph_oid=graph_oid@entry=16978, params=0x628fff4f6ed0) at src/backend/parser/cypher_analyze.c:1144
#14 0x00007bcf9cd8df30 in analyze_cypher_and_coerce (stmt=stmt@entry=0x628fff6331c8, rtfunc=rtfunc@entry=0x628fff4cf608, parent_pstate=parent_pstate@entry=0x628fff4f6718, query_str=query_str@entry=0x628fff4cf3e8 "MATCH (n $props) RETURN n ",
    query_loc=query_loc@entry=70, graph_name=graph_name@entry=0x628fff4cf348 "cypher_match", graph_oid=16978, params=0x628fff4f6ed0) at src/backend/parser/cypher_analyze.c:1190
#15 0x00007bcf9cd8ea74 in convert_cypher_to_subquery (rte=rte@entry=0x628fff4f69d8, pstate=pstate@entry=0x628fff4f6718) at src/backend/parser/cypher_analyze.c:622
#16 0x00007bcf9cd8eb09 in convert_cypher_walker (node=node@entry=0x628fff4f69d8, pstate=pstate@entry=0x628fff4f6718) at src/backend/parser/cypher_analyze.c:138
#17 0x0000628ffe38051e in range_table_entry_walker_impl (rte=0x628fff4f69d8, walker=walker@entry=0x7bcf9cd8ea82 <convert_cypher_walker>, context=context@entry=0x628fff4f6718, flags=flags@entry=21) at nodeFuncs.c:2700
#18 0x0000628ffe38063d in range_table_walker_impl (rtable=0x628fff4cf9f0, walker=walker@entry=0x7bcf9cd8ea82 <convert_cypher_walker>, context=context@entry=0x628fff4f6718, flags=flags@entry=21) at nodeFuncs.c:2679
#19 0x0000628ffe3807f3 in query_tree_walker_impl (query=query@entry=0x628fff4f6828, walker=walker@entry=0x7bcf9cd8ea82 <convert_cypher_walker>, context=context@entry=0x628fff4f6718, flags=flags@entry=21) at nodeFuncs.c:2656
#20 0x00007bcf9cd8ec65 in convert_cypher_walker (node=node@entry=0x628fff4f6828, pstate=pstate@entry=0x628fff4f6718) at src/backend/parser/cypher_analyze.c:259
#21 0x00007bcf9cd8ecb2 in post_parse_analyze (pstate=0x628fff4f6718, query=0x628fff4f6828, jstate=<optimized out>) at src/backend/parser/cypher_analyze.c:101
#22 0x0000628ffe212591 in parse_analyze_varparams (parseTree=parseTree@entry=0x628fff4f6d18,
    sourceText=sourceText@entry=0x628fff391f98 "PREPARE property_ps(agtype) AS SELECT * FROM cypher('cypher_match', $$MATCH (n $props) RETURN n $$, $1) AS (p agtype);", paramTypes=paramTypes@entry=0x7ffd2b5e5170,
    numParams=numParams@entry=0x7ffd2b5e516c, queryEnv=queryEnv@entry=0x0) at analyze.c:172
#23 0x0000628ffe4d9878 in pg_analyze_and_rewrite_varparams (parsetree=parsetree@entry=0x628fff4f6d18,
    query_string=0x628fff391f98 "PREPARE property_ps(agtype) AS SELECT * FROM cypher('cypher_match', $$MATCH (n $props) RETURN n $$, $1) AS (p agtype);", paramTypes=paramTypes@entry=0x7ffd2b5e5170, numParams=numParams@entry=0x7ffd2b5e516c,
    queryEnv=queryEnv@entry=0x0) at postgres.c:727
#24 0x0000628ffe2a6979 in PrepareQuery (pstate=pstate@entry=0x628fff4f6c08, stmt=stmt@entry=0x628fff3932a8, stmt_location=<optimized out>, stmt_len=<optimized out>) at prepare.c:119
#25 0x0000628ffe4dfad1 in standard_ProcessUtility (pstmt=pstmt@entry=0x628fff393358,
    queryString=queryString@entry=0x628fff391f98 "PREPARE property_ps(agtype) AS SELECT * FROM cypher('cypher_match', $$MATCH (n $props) RETURN n $$, $1) AS (p agtype);", readOnlyTree=readOnlyTree@entry=false,
    context=context@entry=PROCESS_UTILITY_TOPLEVEL, params=params@entry=0x0, queryEnv=queryEnv@entry=0x0, dest=0x628fff393618, qc=0x7ffd2b5e5510) at utility.c:752
#26 0x00007bcf9cd8126a in ag_ProcessUtility_hook (pstmt=0x628fff393358, queryString=0x628fff391f98 "PREPARE property_ps(agtype) AS SELECT * FROM cypher('cypher_match', $$MATCH (n $props) RETURN n $$, $1) AS (p agtype);", readOnlyTree=<optimized out>,
    context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0x628fff393618, qc=0x7ffd2b5e5510) at src/backend/catalog/ag_catalog.c:109
#27 0x0000628ffe4e011e in ProcessUtility (pstmt=pstmt@entry=0x628fff393358, queryString=<optimized out>, readOnlyTree=<optimized out>, context=context@entry=PROCESS_UTILITY_TOPLEVEL, params=<optimized out>, queryEnv=<optimized out>,
    dest=0x628fff393618, qc=0x7ffd2b5e5510) at utility.c:526
#28 0x0000628ffe4dd656 in PortalRunUtility (portal=portal@entry=0x628fff40f2a8, pstmt=pstmt@entry=0x628fff393358, isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=false, dest=dest@entry=0x628fff393618,
    qc=qc@entry=0x7ffd2b5e5510) at pquery.c:1158
#29 0x0000628ffe4dd91f in PortalRunMulti (portal=portal@entry=0x628fff40f2a8, isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=false, dest=dest@entry=0x628fff393618, altdest=altdest@entry=0x628fff393618,
    qc=qc@entry=0x7ffd2b5e5510) at pquery.c:1315
#30 0x0000628ffe4ddc90 in PortalRun (portal=portal@entry=0x628fff40f2a8, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true, run_once=run_once@entry=true, dest=dest@entry=0x628fff393618, altdest=altdest@entry=0x628fff393618,
    qc=0x7ffd2b5e5510) at pquery.c:791
#31 0x0000628ffe4d9fdd in exec_simple_query (query_string=query_string@entry=0x628fff391f98 "PREPARE property_ps(agtype) AS SELECT * FROM cypher('cypher_match', $$MATCH (n $props) RETURN n $$, $1) AS (p agtype);") at postgres.c:1274
#32 0x0000628ffe4dbe2f in PostgresMain (dbname=<optimized out>, username=<optimized out>) at postgres.c:4637
#33 0x0000628ffe43dede in BackendRun (port=port@entry=0x628fff3bf400) at postmaster.c:4464
#34 0x0000628ffe43fef6 in BackendStartup (port=port@entry=0x628fff3bf400) at postmaster.c:4192
#35 0x0000628ffe440094 in ServerLoop () at postmaster.c:1782
#36 0x0000628ffe4415d0 in PostmasterMain (argc=argc@entry=3, argv=argv@entry=0x628fff34bfe0) at postmaster.c:1466
#37 0x0000628ffe366205 in main (argc=3, argv=0x628fff34bfe0) at main.c:198

Expected behavior:
Expected ERROR to be shown or sql query to be successfully executed

Best regards,
Egor Chindyaskin
Postgres Professional: https://postgrespro.com/

Activity

  1. added
    bug
    on Jul 9, 2024
  2. github-actions commented on Sep 8, 2024

    @github-actions

    This issue is stale because it has been open 60 days with no activity. Remove "Abondoned" label or comment or this will be closed in 14 days.

  3. added
    Stale
    on Sep 8, 2024
  4. added
    override-stale
    and removed
    Stale
    on Sep 8, 2024
  5. added a commit that references this issue on Feb 26, 2026
    5697e86
  6. gregfelice commented on Feb 26, 2026

    @gregfelice
    Contributor

    Fix submitted in #2338. The crash occurs because create_property_constraints casts cypher_param nodes to cypher_map* in the non-containment code path (age.enable_containment = off), then dereferences keyvals which maps to the name char pointer — reading invalid memory. The fix falls back to the containment operator for parameterized constraints since map decomposition requires known keys at parse time.

  7. gregfelice commented on Feb 26, 2026

    @gregfelice
    Contributor

    Fix submitted in #2339. The crash occurs because create_property_constraints casts cypher_param nodes to cypher_map* in the non-containment code path (age.enable_containment = off), then dereferences keyvals which maps to the name char pointer — reading invalid memory.

  8. added a commit that references this issue on Feb 28, 2026
    e4fba70
  9. added a commit that references this issue on Mar 4, 2026
    23146a4
  10. added a commit that references this issue on Sep 18, 2026
    62280c2
  11. added a commit that references this issue on Sep 18, 2026
    aa9825b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugoverride-stale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions