Repository navigation
Make check_stack_depth() effective for embedders; guard recursive output paths #10
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: 18-constructive
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -146,3 +146,14 @@ stack_is_too_deep(void) | |
| #if defined(HAVE_GETRLIMIT) | ||
| #else | ||
| #endif | ||
|
|
||
| /* 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 = (ssize_t) bytes; | ||
| max_stack_depth = (int) (bytes / 1024); | ||
| } | ||
|
Comment on lines
+151
to
+159
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 New The PR adds 📋 Prompt for AI AgentsIn the libpg_query repo: (1) add |
||
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 · medium
Serialize-on-parse-error path left outside
PG_TRYIn
pg_query_parse_optsthe newPG_TRYonly covers theresult.error == NULLbranch; theelsebranch still callspg_query_nodes_to_jsonon the partial tree with no handler (src/pg_query_parse.c:167-169).check_stack_depth()in_outNode(src/pg_query_outfuncs_json.c:293) can throw for a deeply nested partial statement on exactly this error path, and the uncaught throw skipspg_query_exit_memory_contextand terminates the process. Restructuring the code so the error branch runs outside the try block creates the gap; the throw can be caught as easily as the success branch.📋 Prompt for AI Agents
In src/pg_query_parse.c, pg_query_parse_opts lines 138-170: remove the
if (result.error == NULL) ... else ...split and run the pg_query_nodes_to_json/strdup/pfree sequence unconditionally inside the existing PG_TRY block, keeping the PG_CATCH that builds a PgQueryError. When a parse error already exists, the partial tree is still serialized, but a check_stack_depth()/ereport throw during serialization is caught and reported instead of longjmping out of the library unguarded.