[PR #2102] [MERGED] fix(wasm): preserve leading BOM in custom section names #5029

Closed
opened 2026-10-31 00:59:01 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/2102
Author: @1052326311
Created: 10/12/2026
Status: ✅ Merged
Merged: 10/12/2026
Merged by: @morluto

Base: main ← Head: fix/wasm-custom-name-bom


📝 Commits (1)

  • e800a2c fix(wasm): preserve leading BOM in custom section names

📊 Changes

5 files changed (+30 additions, -5 deletions)

View changed files

📝 scripts/verify-wasm-artifact.mjs (+4 -0)
📝 src/wasm/WabtOutput.test.ts (+14 -1)
📝 src/wasm/WabtWat.ts (+5 -3)
📝 tests/fixtures/wasm/README.md (+2 -0)
📝 tests/fixtures/wasm/custom-names.wat (+5 -1)

📄 Description

Summary

Preserve leading U+FEFF in WABT custom-section names so valid WASM modules return Evidence instead of unreadable_output.

No existing issue covers this specific decoding error. Searches for WabtWat, WABT BOM, and custom-section names found the already merged NUL-display fix #1981 and debug-name fix #1967; neither preserves leading U+FEFF during custom-name decoding.

Problem and expected behavior

Compile this valid fixture with WABT 1.0.42 wat2wasm --enable-all:

(module (@custom "\ef\bb\bfname" "payload"))

WASM names are length-delimited UTF-8. U+FEFF is part of the name, not stream framing. TextDecoder currently removes it, turning the name into the special name section and attempting to parse arbitrary payload as debug metadata. The real CLI returns unreadable_output with Incomplete WABT name-section metadata.. Other leading-U+FEFF names disagree with the exact objdump header and are also rejected.

Expected: preserve the complete name and return the original producer output and Evidence.

Change and scope

Use ignoreBOM: true for custom names, matching the existing module-name decoder. Extend the existing producer fixture and CLI/MCP verifier for leading U+FEFF, U+FEFF followed by name, and U+FEFF-only versus empty names. Retain fatal UTF-8 decoding and existing framing, range, NUL-display and actual debug-name controls.

Contract and boundary impact

  • Semantic owner and earliest changed stage: parseWabtWat, decoding length-delimited custom names.
  • CLI and MCP/tool-catalog contract: unchanged schemas; valid modules previously rejected now return Evidence.
  • Provider, bridge, target-format, or platform compatibility: existing WABT 1.0.42 profile.
  • Evidence, artifact, provenance, or reconstruction contract: retain exact names, original WAT, header/details text, digests and section extents.
  • Process execution, authorization, cleanup, or containment impact: none.
  • Generated metadata, package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: one focused parser regression plus existing custom-names.wat and real-tool verifier expectations. Invalid UTF-8 remains rejected.

  • Base reproduction: on main 79156e5bed1d72b83ade0483246f457b337b7e59, the new parser regression fails (11 controls pass). The compiled real-tool lane also fails at the CLI result for the expanded custom-name fixture, despite successful WABT validation.

  • User-visible CLI/MCP output: before, unreadable_output / Incomplete WABT name-section metadata.; after, both surfaces return equal Evidence with descriptions retaining U+FEFF. The verifier checks unmodified bytes, exact WAT/header/detail output, digests, and retained evidence bundles.

  • Remaining proof gaps: no Windows/Linux execution or full deterministic suite; hosted CI remains separate.

  • 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

Executed on macOS arm64 with Node 24.18.0, npm 11.16.0 and upstream WABT 1.0.42 (release archive SHA-256 verified):

  • npm run test:local -- src/wasm/WabtOutput.test.ts src/wasm/WabtArtifactProvider.test.ts src/application/wasm/WasmArtifactService.test.ts - 32 tests passed.
  • REA_WABT_BIN_DIRECTORY=<absolute WABT bin> npm run verify:wasm:artifact -- --require-tools - 42 cases passed through compiled CLI and stdio MCP, including valid and malformed modules.
  • npm run check - all six tasks and architecture guards passed. An earlier attempt stopped on the build command lock before checks ran; the sequential retry completed.
  • git diff --check - passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: real WABT on macOS arm64; other providers not involved.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new authority; fatal UTF-8 decoding and exact output framing remain enforced.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • The PR has one focused outcome and a conventional title.
  • Reason for not linking an issue is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs and contracts are updated where needed; schemas are unchanged.
  • User-visible CLI/MCP changes include representative output.
  • Final diff checked for secrets, unrelated cleanup, and unsupported claims. Pre-commit also removed one redundant quote escape in an existing test string without changing its value.

🔄 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/2102 **Author:** [@1052326311](https://github.com/1052326311) **Created:** 10/12/2026 **Status:** ✅ Merged **Merged:** 10/12/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/wasm-custom-name-bom` --- ### 📝 Commits (1) - [`e800a2c`](https://github.com/morluto/rea/commit/e800a2c8223a28b890d42139ee10dabbcc1d418d) fix(wasm): preserve leading BOM in custom section names ### 📊 Changes **5 files changed** (+30 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `scripts/verify-wasm-artifact.mjs` (+4 -0) 📝 `src/wasm/WabtOutput.test.ts` (+14 -1) 📝 `src/wasm/WabtWat.ts` (+5 -3) 📝 `tests/fixtures/wasm/README.md` (+2 -0) 📝 `tests/fixtures/wasm/custom-names.wat` (+5 -1) </details> ### 📄 Description ## Summary Preserve leading U+FEFF in WABT custom-section names so valid WASM modules return Evidence instead of `unreadable_output`. No existing issue covers this specific decoding error. Searches for `WabtWat`, `WABT BOM`, and custom-section names found the already merged NUL-display fix #1981 and debug-name fix #1967; neither preserves leading U+FEFF during custom-name decoding. ## Problem and expected behavior Compile this valid fixture with WABT 1.0.42 `wat2wasm --enable-all`: ```wat (module (@custom "\ef\bb\bfname" "payload")) ``` WASM names are length-delimited UTF-8. U+FEFF is part of the name, not stream framing. `TextDecoder` currently removes it, turning the name into the special `name` section and attempting to parse arbitrary payload as debug metadata. The real CLI returns `unreadable_output` with `Incomplete WABT name-section metadata.`. Other leading-U+FEFF names disagree with the exact objdump header and are also rejected. Expected: preserve the complete name and return the original producer output and Evidence. ## Change and scope Use `ignoreBOM: true` for custom names, matching the existing module-name decoder. Extend the existing producer fixture and CLI/MCP verifier for leading U+FEFF, U+FEFF followed by `name`, and U+FEFF-only versus empty names. Retain fatal UTF-8 decoding and existing framing, range, NUL-display and actual debug-name controls. ## Contract and boundary impact - Semantic owner and earliest changed stage: `parseWabtWat`, decoding length-delimited custom names. - CLI and MCP/tool-catalog contract: unchanged schemas; valid modules previously rejected now return Evidence. - Provider, bridge, target-format, or platform compatibility: existing WABT 1.0.42 profile. - Evidence, artifact, provenance, or reconstruction contract: retain exact names, original WAT, header/details text, digests and section extents. - Process execution, authorization, cleanup, or containment impact: none. - Generated metadata, package, or installation impact: none. ## Evidence and regression coverage - Tests added or updated: one focused parser regression plus existing `custom-names.wat` and real-tool verifier expectations. Invalid UTF-8 remains rejected. - Base reproduction: on main `79156e5bed1d72b83ade0483246f457b337b7e59`, the new parser regression fails (11 controls pass). The compiled real-tool lane also fails at the CLI result for the expanded custom-name fixture, despite successful WABT validation. - User-visible CLI/MCP output: before, `unreadable_output` / `Incomplete WABT name-section metadata.`; after, both surfaces return equal Evidence with descriptions retaining U+FEFF. The verifier checks unmodified bytes, exact WAT/header/detail output, digests, and retained evidence bundles. - Remaining proof gaps: no Windows/Linux execution or full deterministic suite; hosted CI remains separate. - [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 Executed on macOS arm64 with Node 24.18.0, npm 11.16.0 and upstream WABT 1.0.42 (release archive SHA-256 verified): - `npm run test:local -- src/wasm/WabtOutput.test.ts src/wasm/WabtArtifactProvider.test.ts src/application/wasm/WasmArtifactService.test.ts` - 32 tests passed. - `REA_WABT_BIN_DIRECTORY=<absolute WABT bin> npm run verify:wasm:artifact -- --require-tools` - 42 cases passed through compiled CLI and stdio MCP, including valid and malformed modules. - `npm run check` - all six tasks and architecture guards passed. An earlier attempt stopped on the build command lock before checks ran; the sequential retry completed. - `git diff --check` - passed. ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: real WABT on macOS arm64; other providers not involved. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no new authority; fatal UTF-8 decoding and exact output framing remain enforced. ## Review checklist - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] The PR has one focused outcome and a conventional title. - [x] Reason for not linking an issue is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs and contracts are updated where needed; schemas are unchanged. - [x] User-visible CLI/MCP changes include representative output. - [x] Final diff checked for secrets, unrelated cleanup, and unsupported claims. Pre-commit also removed one redundant quote escape in an existing test string without changing its value. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 00:59:01 +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#5029
No description provided.