You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by ji...@apache.org on 2025/07/30 06:18:07 UTC
(cloudberry-pxf) 01/02: Fix stack overflow in add_projection_desc_httpheader_pg12
This is an automated email from the ASF dual-hosted git repository.
jiaqizho pushed a commit to branch github-cherry-pick
in repository https://gitbox.apache.org/repos/asf/cloudberry-pxf.git
commit 7cc229d39391f932b43d295e2e21b99491619e04
Author: WANG Weinan <wa...@hashdata.cn>
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 dd7b4167..4632530e 100644
--- a/external-table/src/pxfheaders.c
+++ b/external-table/src/pxfheaders.c
@@ -537,6 +537,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,
@@ -551,7 +568,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;
@@ -603,8 +622,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++;
}
}
@@ -662,6 +681,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: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org