Skip to content

Size the stack depth limit from the WebAssembly stack in Emscripten builds - #18

Merged
devin-ai-integration[bot] merged 2 commits into
18-constructivefrom
devin/1795659186-wasm-stack-depth
Nov 26, 2026
Merged

devin-ai-integration[bot] merged 2 commits into
18-constructivefrom
devin/1795659186-wasm-stack-depth

Conversation

@pyramation

@pyramation pyramation commented Nov 26, 2026 •

Copy link
Copy Markdown

Summary

get_lowest_stackaddr() had no Emscripten case, so in WASM set_max_stack_depth() always returned early and max_stack_depth stayed at the 100kB default. libpg-query 18.2.6 (built from this branch) rejects SELECT 1+1+… at about 800 terms and 500 nested subqueries with "stack depth limit exceeded"; 18.1.5 parsed them and native builds still do.

#elif defined(__EMSCRIPTEN__)
	pg_query_lowest_stackaddr = (char *) emscripten_stack_get_end();

Under Emscripten the clamp is 512kB instead of 2MB. WASM frames also run on the host engine's native stack (~984kB in Node), where they are larger than on the WASM stack. At 1MB or 2MB, deep inputs (e.g. libpg-query-node's 100k-term test) hit V8's RangeError before our check instead of returning the clean SQL error; 512kB keeps the clean error at Node's default stack and at --stack-size=700.

First failing depth in libpg-query-node (32MiB WASM stack, default Node stack):

Input 18.1.5 18.2.6 this PR
1+1+… 6500 (RangeError) 1000 4000
(SELECT (SELECT … 2000 (RangeError) 500 1500
f(f(… 3500 (RangeError) 1000 3000

All failures with this PR are the clean "stack depth limit exceeded" error. Native builds are unchanged (2MB clamp). The same gap exists in upstream 18-latest.

Tested in libpg-query-node: constructive-io/libpg-query-node#210 adds the regression test (red on the current pin) and pins this branch; the full v18 suite passes (158/158) locally.


libpg-query and parser opened this PR for Dan
Implemented in session Settle the last old WASM hardening PRs
Review with Devin · Open in Devin Desktop


@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@luxor-code-review

luxor-code-review Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This small PR adjusts platform-specific stack-depth handling in src/pg_query.c so libpg_query can build and run safely under Emscripten/WASM, where the linear-memory stack and host engine limits differ from native platforms. | Files | Change | | --- | --- | | src/pg_query.c | Adds an __EMSCRIPTEN__-guarded branch that clamps the maximum stack depth (1024 KB cap) and resolves the stack bounds via wasm-appropriate stack functions before the existing linux/pthread and win32 paths. | | test, Makefile | No test or build-file changes accompany the platform guard; behavior is verified only by the wasm build succeeding. |

Reviewed commit: fd8b6b5

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 273e3b69-e37f-4ef9-a341-ad8e66ff1bc4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant