Skip to content

fix(wasm): inspect modules whose custom section names contain NUL - #1981

Merged
morluto merged 4 commits into
morluto:mainfrom
viniciusdsandrade:fix/wasm-custom-section-nul-names
Oct 12, 2026
Merged

morluto merged 4 commits into
morluto:mainfrom
viniciusdsandrade:fix/wasm-custom-section-nul-names

Conversation

@viniciusdsandrade

Copy link
Copy Markdown
Contributor

Summary

inspect_wasm_artifact / inspect-wasm-artifact rejects a valid module when a custom section name contains U+0000. WABT validates the module, but wasm-objdump -h prints the name only up to the NUL, while the adapter compares that row with the complete name decoded from WAT. Compare it with the displayed prefix instead, the rule #1967 already applies to debug module names.

No existing issue covers this. It is the custom-section counterpart of the module-name display handling merged in #1967.

Problem and expected behavior

WABT 1.0.42 (ff0ef7e0) prints a custom section name in header mode with printf("\"" PRIstringview "\"\n", ...) in BinaryReaderObjdump::BeginCustomSection, and PRIstringview is %.*s, so the output stops at the first NUL. wasm2wat writes the same name as "visible\00hidden", which parseWabtWat decodes to visible\u0000hidden. parseWabtOutput then looks for "visible\u0000hidden" where objdump printed "visible", throws WABT custom-section header does not match decoded WAT., and the tool returns unreadable_output instead of Evidence.

Smallest trigger, compiled with WABT 1.0.42 wat2wasm --enable-all:

(module (@custom "visible\00hidden" "payload"))

U+0000 is valid UTF-8 and WABT reads section names through ReadStr, which only checks UTF-8, so wasm-validate --enable-all accepts the module. Expected: Evidence whose custom section description is the text objdump displayed, "visible".

Change and scope

parseWabtOutput compares each custom-section row with the decoded name up to its first NUL, as it already does for module name: preamble lines. The section description stays objdump's row text, like every other section kind; the complete name remains in the decoded WAT. Malformed rows, names that differ before the NUL, the custom-section inventory count and range checks are still rejected. No schema, contract or WAT decoding change.

Contract and boundary impact

  • Semantic owner and earliest changed stage: WABT objdump output framing in src/wasm/WabtOutput.ts.
  • CLI and MCP/tool-catalog contract: unchanged inputs and schemas; formerly rejected modules return Evidence.
  • Provider, bridge, target-format, or platform compatibility: existing WABT 1.0.42 profile.
  • Evidence, artifact, provenance, or reconstruction contract: header/detail text, decoded WAT, digests and section ranges are unchanged; a custom section description is the displayed name.
  • Process execution, authorization, cleanup, or containment impact: none.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: src/wasm/WabtOutput.test.ts frames the real objdump golden with the decoded name test\0hidden (description "test") and still rejects other\0test. The real-tool fixture tests/fixtures/wasm/custom-names.wat gains visible\00hidden, and scripts/verify-wasm-artifact.mjs expects its "visible" description through CLI and MCP.
  • Base reproduction or other evidence: source-derived, from WABT 1.0.42 binary-reader-objdump.cc (BeginCustomSection), wat-writer.cc (WriteQuotedData escapes byte 0 as \00), wast-parser.cc (ParseQuotedText), binary-reader.cc (ReadStr) and utf8.cc (IsValidUtf8). The first assertion of the new unit test throws on the base revision.
  • User-visible CLI/MCP output (if applicable): before, unreadable_output with reason WABT custom-section header does not match decoded WAT.; after, Evidence with the custom section description "visible".
  • Remaining proof gaps: the real WABT lane (npm run verify:wasm:artifact -- --require-tools) is manual and was not run, and the focused tests were not run locally.

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

  • No local commands were run: this environment has no installed dependencies or WABT tools. The evidence above is source-derived; CI runs the deterministic suite.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: none run.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no added authority. A crafted name still cannot stand in for parser delimiters: the displayed prefix must match the decoded name, and the existing row, inventory and range checks remain.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T22:48:13.980974Z 941eadd New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 031cb379c3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/wasm/WabtOutput.ts Outdated
if (match[1] === "Custom") {
const name = customSectionNames[customIndex++];
// Custom-section names use the same %.*s display as module names.
const name = customSectionNames[customIndex++]?.split("\0", 1)[0];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Centralize the WABT display-name normalization

This adds a second implementation of WABT's NUL-terminated display rule alongside the existing debugModuleNames mapping, leaving module and custom-section framing with independent split("\0", 1) operations that can diverge when this producer-format rule changes again. Normalize display names through one owning helper at this boundary and use it in both paths; the repository explicitly requires bug fixes to eliminate directly related duplicated interpretation.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in ec6b1e2: module-name preamble lines and custom-section rows now share one wabtDisplayedName helper for the NUL-terminated display, with unchanged output.

@CassieFox23

CassieFox23 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: The fix works on Linux: modules with a NUL byte in a custom section name now get Evidence, and bad names are still refused. The PR's real-tool check also passes on the old code. That is because wat2wasm 1.0.42 cuts the fixture's name at the first NUL, so the name is just visible.

Thanks, viniciusdsandrade, for the fix, and here is how it did on my box. I tested head ec6b1e2 against base 55b6148. I used real WABT 1.0.42 (Apache-2.0), over the CLI and over MCP.

I first ran this at 031cb37. The PR then moved to ec6b1e2, a refactor of src/wasm/WabtOutput.ts only. I reran the CLI, MCP, unit tests and PR lane there, and the results are the same.

I wrote the test modules as raw bytes. For (module (@custom "visible\00hidden" "payload")), wat2wasm 1.0.42 wrote 25 bytes, and the name in the file is visible. Raw bytes give 32 bytes and keep the NUL.

How WABT 1.0.42 treats these modules
Module Validate Objdump says Decoded as
NUL in the middle passes (0) "visible" "visible\00hidden"
NUL at the start passes (0) "" "\00hidden"
Bad UTF-8 name fails (1) error, no name fails (1)
Name longer than its section fails (1) error, no name fails (1)

Results

Check Base Head
NUL in the middle, CLI exit 1, unreadable_output: the header does not match the decoded WAT exit 0, Evidence, section "visible"
Same module over MCP tool error with the same code and reason as the CLI row Evidence, same as the CLI
NUL at the start or alone unreadable_output, as in the first row exit 0, section ""
Two sections, dup\0one and dup\0two unreadable_output, as in the first row exit 0, "dup" twice
Three sections, a\0b, plain, c\0d\0e unreadable_output, as in the first row exit 0, "a", "plain", "c"
NUL, then newline and a fake Section Details: line unreadable_output, as in the first row exit 0, one section "ok"
Name name\0junk unreadable_output, as in the first row exit 0, one section "name", not read as a name section
NUL name before and after function code unreadable_output, as in the first row exit 0
Normal name visible exit 0 exit 0, same output as base
Bad UTF-8 name, three variants exit 1, invalid_request, WABT says "invalid utf-8 encoding: section name" same as base
Name longer than its section, two variants exit 1, invalid_request, "unable to read string: section name" same as base

In all 16 raw-byte modules the head output parsed as JSON and held no NUL, raw or escaped as U+0000. The NUL shows only as \00 in the decoded WAT text. The section description is what objdump printed, as the PR says. The MCP and CLI Evidence were equal for the three modules I compared.

Test Node 22.23.1 Node 24.18.0 Node 26.11.1
Two wasm test files on head, 20 tests pass pass pass

On Node 24, I copied head's unit test file onto base. The new unit test failed there with the custom-section header error. So the unit test does catch the bug.

The PR's real-tool lane (npm run verify:wasm:artifact -- --require-tools) passed on head with 42 cases. It also passed on base, and it passed when I ran head's script against base's code. So the "visible" line there does not test the fix. The fixture goes through wat2wasm, which cuts the name at the first NUL. A fixture made from raw bytes would catch it.

Not run

  • Other WABT versions and other platforms. The PR docs say only macOS arm64 was checked before (docs, not verified by me).
  • The base-side runs and the control copy of the test file at ec6b1e2. Base is the same, and the diff between the two heads touches only src/wasm/WabtOutput.ts, so those come from the first run.
  • The full test suite. The box was shared with three other test agents, so I give no timings.
  • A real objdump row that differs from the name before the NUL. WABT cannot print one, so only the unit test covers it.
Commands
# WABT: gh release download 1.0.42 -R WebAssembly/wabt -p 'wabt-1.0.42-linux-x64.tar.gz*'
# sha256 matched 84895407a6bbb80e918f33b16b2fb2206021c150b6bc9ff6f761263a745ab131
export PATH=~/.local/opt/node24/bin:$PATH
export REA_WABT_BIN_DIRECTORY=/tmp/p1981/dl/wabt-unpacked/wabt-1.0.42/bin
# build (both trees): npm ci && npm run build && npm run test:prepare   (all exit 0)
# CLI, per module and tree:
node scripts/rea.mjs inspect-wasm-artifact /tmp/p1981/fix/bin-nul-mid.wasm --format json
# MCP: a small stdio client calling inspect_wasm_artifact on 9 modules, base and head
# PR lane:
npm run verify:wasm:artifact -- --require-tools          # head: exit 0, 42 cases
npm run verify:wasm:artifact -- --require-tools          # base: exit 0, 42 cases
node head/scripts/verify-wasm-artifact.mjs base/scripts/rea.mjs --require-tools   # exit 0, 42 cases
# tests, once per Node (22, 24, 26):
node node_modules/vitest/vitest.mjs run src/wasm/WabtOutput.test.ts src/wasm/WabtArtifactProvider.test.ts
# control: head's WabtOutput.test.ts copied into base -> 1 failed, 9 passed (exit 1)
Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head: ec6b1e2
  • Base: 55b6148
  • Other: WABT 1.0.42 (Apache-2.0)
  • Shared: three other test agents used the box, so I give no timings

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

wasm-objdump prints a custom section name with printf's %.*s, so an
embedded NUL ends the displayed name, as it does for module names.
The section row was compared with the complete name decoded from WAT,
so a valid module whose custom section name contains U+0000 failed
inspection with "WABT custom-section header does not match decoded
WAT". Compare the row with the displayed prefix instead.
Frame the real objdump golden with a decoded custom section name that
continues after a NUL, and keep rejecting a displayed prefix that
differs from the decoded name.
Add a custom section named "visible\0hidden" to the real-tool custom
name fixture. WABT 1.0.42 decodes it as an escaped WAT name and
displays "visible" in wasm-objdump, so the verifier expects that
description through the compiled CLI and MCP.
Module-name preamble lines and custom-section rows each truncated the
decoded name at its first NUL. Keep that display rule in one helper so
both framings follow the same producer behavior. Output is unchanged.
@viniciusdsandrade
viniciusdsandrade force-pushed the fix/wasm-custom-section-nul-names branch from ec6b1e2 to 941eadd Compare October 11, 2026 22:45
@morluto
morluto merged commit 1febc22 into morluto:main Oct 12, 2026
2 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 12, 2026
3 tasks done
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants