You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by mt...@apache.org on 2026/03/26 10:01:25 UTC

(age) 06/20: Fix Issue 2256: segmentation fault when calling coalesce function (#2259)

This is an automated email from the ASF dual-hosted git repository.

mtaha pushed a commit to branch PG16
in repository https://gitbox.apache.org/repos/asf/age.git

commit ae0944b36808643af77b8f141a4dd81084fa4bef
Author: John Gemignani <jr...@gmail.com>
AuthorDate: Tue Dec 9 10:51:01 2025 -0800

    Fix Issue 2256: segmentation fault when calling coalesce function (#2259)
    
    Fixed issue 2256: A segmentation fault occurs when calling the coalesce
    function in PostgreSQL version 17. This likely predates 17 and includes
    other similar types of "functions". And other versions of PostgreSQL.
    
    See issues 1124 (PR 1125) and 1303 (PR 1317) for more details.
    
    This issue is due to coalesce() being processed differently from other
    functions. Additionally, greatest() was found to exhibit the same
    behavior. They were added to the list of types to ignore during the
    cypher analyze phase.
    
    A few others were added: CaseExpr, XmlExpr, ArrayExpr, & RowExpr.
    Although, I wasn't able to find cases where these caused crashes.
    
    Added regression tests.
    
    modified:   regress/expected/cypher.out
    modified:   regress/sql/cypher.sql
    modified:   src/backend/parser/cypher_analyze.c
    Conflicts:
            src/backend/parser/cypher_analyze.c
---
 regress/expected/cypher.out         | 16 ++++++++++++++++
 regress/sql/cypher.sql              |  7 +++++++
 src/backend/parser/cypher_analyze.c | 26 ++++++++++++++++++++------
 3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/regress/expected/cypher.out b/regress/expected/cypher.out
index 31bafc6c..53ea9f0c 100644
--- a/regress/expected/cypher.out
+++ b/regress/expected/cypher.out
@@ -169,6 +169,22 @@ CREATE TABLE my_edges AS
 -- create a table of 4 columns, u, e, v, p. should be 5 rows
 CREATE TABLE my_detailed_paths AS
     (SELECT * FROM cypher('issue_1767', $$ MATCH p=(u)-[e]->(v) RETURN u,e,v,p $$) as (u agtype, e agtype, v agtype, p agtype));
+--
+-- Issue 2256: A segmentation fault occurs when calling the coalesce function
+--             This also occurs with the greatest function too.
+--
+SELECT * FROM coalesce(1, 0);
+ coalesce 
+----------
+        1
+(1 row)
+
+SELECT * FROM greatest(1, 0);
+ greatest 
+----------
+        1
+(1 row)
+
 -- dump out the tables
 SELECT * FROM my_vertices;
                                u                                
diff --git a/regress/sql/cypher.sql b/regress/sql/cypher.sql
index 7ded61ee..090c7e70 100644
--- a/regress/sql/cypher.sql
+++ b/regress/sql/cypher.sql
@@ -94,6 +94,13 @@ CREATE TABLE my_edges AS
 CREATE TABLE my_detailed_paths AS
     (SELECT * FROM cypher('issue_1767', $$ MATCH p=(u)-[e]->(v) RETURN u,e,v,p $$) as (u agtype, e agtype, v agtype, p agtype));
 
+--
+-- Issue 2256: A segmentation fault occurs when calling the coalesce function
+--             This also occurs with the greatest function too.
+--
+SELECT * FROM coalesce(1, 0);
+SELECT * FROM greatest(1, 0);
+
 -- dump out the tables
 SELECT * FROM my_vertices;
 SELECT * FROM my_edges;
diff --git a/src/backend/parser/cypher_analyze.c b/src/backend/parser/cypher_analyze.c
index d53fba3e..ba703fb0 100644
--- a/src/backend/parser/cypher_analyze.c
+++ b/src/backend/parser/cypher_analyze.c
@@ -169,13 +169,20 @@ static bool convert_cypher_walker(Node *node, ParseState *pstate)
          * Const - constant value or expression node
          * BoolExpr - expression node for the basic Boolean operators AND, OR, NOT
          *
-         * These are a special case that needs to be ignored.
+         * Added the following, although only the first 2 caused crashes in tests -
+         * CoalesceExpr, MinMaxExpr, CaseExpr, XmlExpr, ArrayExpr, RowExpr
+         *
+         * These are all special case that needs to be ignored.
          *
          */
         if (IsA(funcexpr, SQLValueFunction)
-                || IsA(funcexpr, CoerceViaIO)
-                || IsA(funcexpr, Var)   || IsA(funcexpr, OpExpr)
-                || IsA(funcexpr, Const) || IsA(funcexpr, BoolExpr))
+            || IsA(funcexpr, CoerceViaIO)
+            || IsA(funcexpr, Var)   || IsA(funcexpr, OpExpr)
+            || IsA(funcexpr, Const) || IsA(funcexpr, BoolExpr)
+            || IsA(funcexpr, JsonConstructorExpr)
+            || IsA(funcexpr, CoalesceExpr) || IsA(funcexpr, MinMaxExpr)
+            || IsA(funcexpr, CaseExpr) || IsA(funcexpr, XmlExpr)
+            || IsA(funcexpr, ArrayExpr) || IsA(funcexpr, RowExpr))
         {
             return false;
         }
@@ -341,13 +348,20 @@ static bool is_func_cypher(FuncExpr *funcexpr)
      * Const - constant value or expression node
      * BoolExpr - expression node for the basic Boolean operators AND, OR, NOT
      *
-     * These are a special case that needs to be ignored.
+     * Added the following, although only the first 2 caused crashes in tests -
+     * CoalesceExpr, MinMaxExpr, CaseExpr, XmlExpr, ArrayExpr, RowExpr
+     *
+     * These are all special case that needs to be ignored.
      *
      */
     if (IsA(funcexpr, SQLValueFunction)
             || IsA(funcexpr, CoerceViaIO)
             || IsA(funcexpr, Var)   || IsA(funcexpr, OpExpr)
-            || IsA(funcexpr, Const) || IsA(funcexpr, BoolExpr))
+            || IsA(funcexpr, Const) || IsA(funcexpr, BoolExpr)
+            || IsA(funcexpr, JsonConstructorExpr)
+            || IsA(funcexpr, CoalesceExpr) || IsA(funcexpr, MinMaxExpr)
+            || IsA(funcexpr, CaseExpr) || IsA(funcexpr, XmlExpr)
+            || IsA(funcexpr, ArrayExpr) || IsA(funcexpr, RowExpr))
     {
         return false;
     }