You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Size the stack depth limit from the WebAssembly stack in Emscripten builds - #18
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.
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.
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. |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_lowest_stackaddr()had no Emscripten case, so in WASMset_max_stack_depth()always returned early andmax_stack_depthstayed at the 100kB default. libpg-query 18.2.6 (built from this branch) rejectsSELECT 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.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
RangeErrorbefore 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):
1+1+…(SELECT (SELECT …f(f(…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.
Implemented in session Settle the last old WASM hardening PRs
Review with Devin · Open in Devin Desktop