Repository navigation
Make check_stack_depth() effective for embedders; guard recursive output paths (17) #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 17-constructive
Are you sure you want to change the base?
Changes from all commits
5691182
ab619b8
b5c9e69
a09aa96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -826,3 +826,14 @@ stack_is_too_deep(void) | |
| * Disable statement timeout, if active. | ||
| */ | ||
|
|
||
|
|
||
| /* libpg-query-node: set the stack-depth reference point and limit from the embedder. */ | ||
| void | ||
| pg_query_set_stack_limit(size_t bytes) | ||
| { | ||
| char here; | ||
|
|
||
| stack_base_ptr = &here; | ||
| max_stack_depth_bytes = (long) bytes; | ||
| max_stack_depth = (int) (bytes / 1024); | ||
| } | ||
|
Comment on lines
+832
to
+839
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 bug · medium
The new exported 📋 Prompt for AI Agents
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #include "postgres_deparse.h" | ||
|
|
||
| #include "postgres.h" | ||
| #include "miscadmin.h" | ||
| #include "catalog/index.h" | ||
| #include "catalog/pg_am.h" | ||
| #include "catalog/pg_attribute.h" | ||
|
|
@@ -783,6 +784,7 @@ static void deparseCExpr(DeparseState *state, Node *node); | |
| // "a_expr" in gram.y | ||
| static void deparseExpr(DeparseState *state, Node *node, DeparseNodeContext context) | ||
| { | ||
| check_stack_depth(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 bug · medium Statement-level deparse recursion bypasses The PR's 📋 Prompt for AI AgentsIn src/postgres_deparse.c, add |
||
| if (node == NULL) | ||
| return; | ||
| switch (nodeTag(node)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 bug · high
PL/pgSQL JSON dumper's
check_stack_depththrow has no handlerdump_stmtanddump_exprinsrc/pg_query_json_plpgsql.c:143now callcheck_stack_depth(), which throws anereport(ERROR)when nesting exceeds the stack-depth limit. The caller chainpg_query_parse_plpgsql→plpgsqlToJSON(src/pg_query_parse_plpgsql.c:492) has noPG_TRY— the enclosingPG_TRYat line 345 only covers compilation and has already exited by the time the dump runs. With no active exception handler,pg_re_throwpromotes the error to FATAL and exits the host process instead of returning aPgQueryError.📋 Prompt for AI Agents
In src/pg_query_parse_plpgsql.c, inside the loop of pg_query_parse_plpgsql (around lines 487-508), wrap
func_json = plpgsqlToJSON(func_and_error.func);in a PG_TRY/PG_CATCH. In the PG_CATCH, MemoryContextSwitchTo the outer context ctx, CopyErrorData, build a malloc'd PgQueryError with strdup'd message/filename/funcname and NULL context, assign it to result.error, and FlushErrorState — mirroring the existing PG_CATCH at lines 369-388 — then skip appending the function and break out of the loop. This is needed because dump_stmt and dump_expr in src/pg_query_json_plpgsql.c now call check_stack_depth(), which throws an ereport(ERROR); with no handler the error becomes FATAL and exits the process on deeply nested PL/pgSQL input.