Skip to content

Use the whole WebAssembly stack for the stack depth limit - #20

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

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

Conversation

@pyramation

@pyramation pyramation commented Nov 26, 2026 •

Copy link
Copy Markdown

Summary

The 512 kB Emscripten cap from #18 still rejects nesting that libpg-query 18.1.5 parsed. It is worst for PL/pgSQL: each nested block uses about 1.5 kB of WebAssembly stack (dump_stmt and friends), so 512 kB stops at about 350 nested IF/BEGIN/LOOP blocks. 18.1.5 parsed about 3,300 of them, until bison's memory exhausted.

There is no cap that works for every input. Measured with no cap in libpg-query-node (Node 24, 32 MB STACK_SIZE), V8's native stack runs out at very different points on the WebAssembly stack:

Input WASM stack per level WASM stack used when V8 overflows
PL/pgSQL nested blocks ~1,470 B never: bison stops at ~3,300 levels (4.9 MB)
SELECT 1+1+… 144 B 1.38 MB
nested subqueries 368 B 0.93 MB
normalize of 1+1+… 193 B 0.14 MB

So 512 kB is too small for PL/pgSQL, and normalize already overflows V8 at 142 kB, below any useful cap.

This PR drops the WebAssembly clamp. The limit becomes the linked stack minus STACK_DEPTH_SLOP, so the check still keeps the WebAssembly stack from overflowing into the heap. A host-stack overflow is left to the embedder; libpg-query-node turns it into the same stack depth limit exceeded error.

The WASM depth test now parses 1,000 nested IF blocks and 3,000 nested BEGIN blocks with the 32 MB stack. The 100,000-term case, which expects the clean error, now runs in a second build linked with a 1 MB stack, where the check fires before V8's stack runs out. The test commit was pushed first and fails on the 512 kB cap.


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.


This PR extends the WebAssembly stack-depth test harness with a new check_plpgsql_depth helper that builds nested PL/pgSQL IF/BEGIN block queries and verifies the parser either parses them or reports a stack-depth error instead of crashing. A new overflow CLI mode runs with 100000 chained terms under a reduced 1MB stack so the parser's own depth guard fires before the host engine's native stack is exhausted.

Files Change
test/wasm_depth.c Adds check_plpgsql_depth() for nested PL/pgSQL block queries and an overflow argument mode selecting the deep chained-terms test.
.github/workflows/ci.yml Builds and runs test/wasm_depth_small.js with a 1MB stack and the overflow argument after the existing 32MB-stack test run.

Reviewed commit: 83823ad

@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: 3fcbb1ae-3a0b-42f5-9f21-45a2c1253fcf

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

@devin-ai-integration

Copy link
Copy Markdown

Closing this. We're keeping the 512 kB WebAssembly cap and the current stack setup. libpg-query-node will report host stack overflows as stack depth errors instead (constructive-io/libpg-query-node#213).

@devin-ai-integration

Copy link
Copy Markdown

Reopening: we're removing the 512 kB cap we added in #18. The limit is now the real WASM stack, and libpg-query-node reports host stack overflows as clean stack depth errors.

@devin-ai-integration
devin-ai-integration Bot merged commit f9f1b67 into 18-constructive Nov 26, 2026
50 checks passed
devin-ai-integration Bot pushed a commit to constructive-io/libpg-query-node that referenced this pull request Nov 26, 2026
devin-ai-integration Bot pushed a commit to constructive-io/libpg-query-node that referenced this pull request Nov 26, 2026
…ck depth errors (#213)

* test(wasm): parse 18.1.5's depths and report V8 stack overflows as stack depth errors

* test(wasm): check parsePlPgSQL's function list and drop a fingerprint case that now parses

* fix(wasm): report host stack overflows as stack depth errors and use the full WASM stack

* test(wasm): keep the stack depth errors in the heap-release test

* fix(wasm): format the overflow's stack so a kept error doesn't pin the dropped instance

* test(release-diff): allow 18.2.7's capped depth limits; lower SQL depths that overflow V8 on macOS

* chore(v18): pin libpg_query to 18-constructive f9f1b67 (constructive-io/libpg_query#20)

* test(v18): drop nested function calls from the 18.1.5 depth test; V8 overflows first on macOS
devin-ai-integration Bot pushed a commit to constructive-io/libpg-query-node that referenced this pull request Nov 26, 2026
* test(wasm): parse 18.1.5's depths and report V8 stack overflows as stack depth errors

* test(wasm): check parsePlPgSQL's function list and drop a fingerprint case that now parses

* fix(wasm): report host stack overflows as stack depth errors and use the full WASM stack

* test(wasm): keep the stack depth errors in the heap-release test

* fix(wasm): format the overflow's stack so a kept error doesn't pin the dropped instance

* test(release-diff): allow 18.2.7's capped depth limits; lower SQL depths that overflow V8 on macOS

* test(wasm): normalize deep nesting on an instance that replaced an overflowed one

* fix(wasm): pin libpg_query with normalize off the per-level PG_TRY path

* chore(v18): pin libpg_query to 18-constructive f9f1b67 (constructive-io/libpg_query#20)

* Pin libpg_query to the fingerprint frame fix

* test(v18): run the fingerprint and normalize depth tests on Node 20 and raise the normalize limits

* chore(v18): pin libpg_query to the fingerprint fix merged with 18-constructive

* chore(v18): pin libpg_query to 18-constructive with both depth fixes
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