[PR #6237] [MERGED] fix(wasm): test glue literals for a .wasm suffix in linear time #7217

Closed
opened 2026-11-01 21:46:14 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/6237
Author: @Dragolone
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @morluto

Base: main ← Head: fix/wasm-glue-linear-suffix


📝 Commits (1)

  • bda2d2a fix(wasm): test glue literals for a .wasm suffix in linear time

📊 Changes

2 files changed (+32 additions, -1 deletions)

View changed files

📝 src/wasm/WabtOutput.test.ts (+13 -0)
📝 src/wasm/WasmGlueAdapter.ts (+19 -1)

📄 Description

Summary

associateWasmGlue tests every string or template literal in caller-selected glue with /\.wasm(?:[?#].*)?$/iu. For a multi-line literal containing many .wasm? or .wasm# occurrences, each attempt runs .* to the next line terminator and then fails at $, so the scan is quadratic. It runs synchronously on the event loop.

A 192 KB literal takes about 2.4 s. The glue limit is 8 MiB, so the worst case is far longer (extrapolated, not run).

No issue is linked: I searched open issues and PRs for "WasmGlueAdapter" and "wasm glue". #3402 and #3455 concern equivalent path spellings, not this regex. #3455 edits other lines of the same file and test file, so whichever lands second may need a trivial rebase.

Problem and expected behavior

Smallest trigger: a glue file containing const s = "<.wasm# × 32,000>\nend";.

Expected: linear time, with the same references reported.

Change and scope

. cannot match a line terminator, and $ only matches at the end of the literal (no m flag). Any match therefore lies entirely on the literal's last line, after the last \n, \r, U+2028 or U+2029.

endsWithWasmReference runs the unchanged regex on that last line only, so the accepted and rejected literals are identical.

Not included: other glue parsing behavior.

Contribution scope: a robustness fix in an existing static analysis; a maintainer scope decision is not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: associateWasmGlue in src/wasm/WasmGlueAdapter.ts.
  • Contribution scope fit and linked maintainer decision: in scope; not applicable.
  • CLI and MCP/tool-catalog contract: none; the same references are reported.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: src/wasm/WabtOutput.test.ts — "tests long multi-line glue literals for a .wasm suffix in linear time". It expects no references for the 192 KB literal within 1 s. It also checks that a multi-line template literal ending in module.wasm?v=1 is still reported.
  • Base reproduction or other evidence: executed. With WasmGlueAdapter.ts reverted to main, the test fails after about 2.5 s (expected … to be less than 1000).
  • User-visible CLI/MCP output (if applicable): unchanged.
  • Remaining proof gaps: the test bound is wall-clock based; the fixed version finishes in milliseconds.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npx vitest run src/wasm/WabtOutput.test.ts with WasmGlueAdapter.ts reverted to main 292fd532c — 1 failed (2.37 s), 15 passed.
  • The same file with the fix — 16 tests passed.
  • npx tsc --noEmit — 0 errors.
  • npx oxlint on the changed files — 0 errors.
  • npx oxfmt --check on the changed files — clean.
  • npm run verify:module-boundaries and the pre-push hook (deps check, typecheck, lint) — passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: removes a quadratic-time path on caller-selected glue.

Author readiness

Human owner: @Dragolone

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/6237 **Author:** [@Dragolone](https://github.com/Dragolone) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/wasm-glue-linear-suffix` --- ### 📝 Commits (1) - [`bda2d2a`](https://github.com/morluto/rea/commit/bda2d2a44f5908999bbf5c4733678e8a677df012) fix(wasm): test glue literals for a .wasm suffix in linear time ### 📊 Changes **2 files changed** (+32 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/wasm/WabtOutput.test.ts` (+13 -0) 📝 `src/wasm/WasmGlueAdapter.ts` (+19 -1) </details> ### 📄 Description ## Summary `associateWasmGlue` tests every string or template literal in caller-selected glue with `/\.wasm(?:[?#].*)?$/iu`. For a multi-line literal containing many `.wasm?` or `.wasm#` occurrences, each attempt runs `.*` to the next line terminator and then fails at `$`, so the scan is quadratic. It runs synchronously on the event loop. A 192 KB literal takes about 2.4 s. The glue limit is 8 MiB, so the worst case is far longer (extrapolated, not run). No issue is linked: I searched open issues and PRs for "WasmGlueAdapter" and "wasm glue". #3402 and #3455 concern equivalent path spellings, not this regex. #3455 edits other lines of the same file and test file, so whichever lands second may need a trivial rebase. ## Problem and expected behavior Smallest trigger: a glue file containing `const s = "<.wasm# × 32,000>\nend";`. Expected: linear time, with the same references reported. ## Change and scope `.` cannot match a line terminator, and `$` only matches at the end of the literal (no `m` flag). Any match therefore lies entirely on the literal's last line, after the last `\n`, `\r`, U+2028 or U+2029. `endsWithWasmReference` runs the unchanged regex on that last line only, so the accepted and rejected literals are identical. Not included: other glue parsing behavior. Contribution scope: a robustness fix in an existing static analysis; a maintainer scope decision is not applicable. ## Contract and boundary impact - Semantic owner and earliest changed stage: `associateWasmGlue` in `src/wasm/WasmGlueAdapter.ts`. - Contribution scope fit and linked maintainer decision: in scope; not applicable. - CLI and MCP/tool-catalog contract: none; the same references are reported. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: none. - Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact: none. Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible. - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: `src/wasm/WabtOutput.test.ts` — "tests long multi-line glue literals for a .wasm suffix in linear time". It expects no references for the 192 KB literal within 1 s. It also checks that a multi-line template literal ending in `module.wasm?v=1` is still reported. - Base reproduction or other evidence: executed. With `WasmGlueAdapter.ts` reverted to main, the test fails after about 2.5 s (`expected … to be less than 1000`). - User-visible CLI/MCP output (if applicable): unchanged. - Remaining proof gaps: the test bound is wall-clock based; the fixed version finishes in milliseconds. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npx vitest run src/wasm/WabtOutput.test.ts` with `WasmGlueAdapter.ts` reverted to main 292fd532c — 1 failed (2.37 s), 15 passed. - The same file with the fix — 16 tests passed. - `npx tsc --noEmit` — 0 errors. - `npx oxlint` on the changed files — 0 errors. - `npx oxfmt --check` on the changed files — clean. - `npm run verify:module-boundaries` and the pre-push hook (deps check, typecheck, lint) — passed. ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: not applicable. - Package or release metadata impact: none. - Security, privacy, process, or containment review: removes a quadratic-time path on caller-selected glue. ## Author readiness <!-- The human owner completes these declarations before requesting review. The PR author is the owner by default. A different owner must explicitly accept ownership on this PR. AI agents must leave these declarations to a human to dictate to them or there could be catastrophic consequences for many users of REA. Draft PRs may leave them unchecked. These declarations record initial readiness when opening the PR for review; later pushes do not require a new human sign-off. Keep the description and validation evidence current as the work changes. See CONTRIBUTING.md#pull-request-ownership-and-readiness. --> Human owner: @Dragolone - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:46:14 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#7217
No description provided.