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

djwang pushed a commit to branch merge-with-upstream
in repository https://gitbox.apache.org/repos/asf/cloudberry-pxf.git

commit 8839ece689f91d39d7aedc09bf1f5ad5ead80ce2
Author: WANG Weinan <[email protected]>
AuthorDate: Tue Jun 24 18:36:44 2025 +0800

    Fix stack overflow in add_projection_desc_httpheader_pg12
---
 external-table/src/pxfheaders.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/external-table/src/pxfheaders.c b/external-table/src/pxfheaders.c
index 583384a3..9ddbbbbe 100644
--- a/external-table/src/pxfheaders.c
+++ b/external-table/src/pxfheaders.c
@@ -651,6 +651,23 @@ add_projection_desc_httpheader_pg94(CHURL_HEADERS headers,
  */
 
 #if PG_VERSION_NUM >= 120000
+static void
+set_var_number(int **varNumbers, int *varNumberSize, int value, int offset)
+{
+       if (*varNumberSize == 0)
+       {
+               *varNumberSize = Max(32, offset * 2);
+               *varNumbers = (int *) palloc0(sizeof(int) * (*varNumberSize));
+       }
+       else if (*varNumberSize <= offset)
+       {
+               *varNumberSize = Max(*varNumberSize * 2, offset * 2);
+               *varNumbers = (int *) repalloc(*varNumbers, sizeof(int) * 
(*varNumberSize));
+       }
+
+       *varNumbers[offset] = value;
+}
+
 static void
 add_projection_desc_httpheader_pg12(CHURL_HEADERS headers,
                  ProjectionInfo *projInfo,
@@ -665,7 +682,9 @@ add_projection_desc_httpheader_pg12(CHURL_HEADERS headers,
     // In versions < 120000, projInfo->pi_varNumbers contains atttribute 
numbers of SimpleVars
     // Since,this pi_varNumbers doesn't exist in PG12 and above, we can add 
the attribute numbers by
     // iterating on the Simple vars.
-  int       varNumbers[sizeof(int32) * 8];
+  
+  int       varNumbersSize = 0;
+  int       *varNumbers = NULL;
   Bitmapset   *attrs_used;
   StringInfoData  formatter;
   TupleDesc   tupdesc;
@@ -717,8 +736,8 @@ add_projection_desc_httpheader_pg12(CHURL_HEADERS headers,
         add_projection_index_header(headers,
                       formatter, attno - 1, long_number);
         numTargetList++;
-                varNumbers[i] = attno;
-                i++;
+               set_var_number(&varNumbers, &varNumbersSize, attno, i);
+               i++;
       }
     }
 
@@ -776,6 +795,9 @@ add_projection_desc_httpheader_pg12(CHURL_HEADERS headers,
     }
   }
 
+  if (varNumbers)
+       pfree(varNumbers);
+
   list_free(qualsAttributes);
   pfree(formatter.data);
   bms_free(attrs_used);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to