Repository navigation
fix(wasm): inspect modules whose custom section names contain NUL - #1981
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| 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]; |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
Addressed in ec6b1e2: module-name preamble lines and custom-section rows now share one wabtDisplayedName helper for the NUL-terminated display, with unchanged output.
|
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 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 I wrote the test modules as raw bytes. For How WABT 1.0.42 treats these modules
Results
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
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 ( Not run
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🤖 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.
ec6b1e2 to
941eadd
Compare
Summary
inspect_wasm_artifact/inspect-wasm-artifactrejects a valid module when a custom section name contains U+0000. WABT validates the module, butwasm-objdump -hprints 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 withprintf("\"" PRIstringview "\"\n", ...)inBinaryReaderObjdump::BeginCustomSection, andPRIstringviewis%.*s, so the output stops at the first NUL.wasm2watwrites the same name as"visible\00hidden", whichparseWabtWatdecodes tovisible\u0000hidden.parseWabtOutputthen looks for"visible\u0000hidden"where objdump printed"visible", throwsWABT custom-section header does not match decoded WAT., and the tool returnsunreadable_outputinstead of Evidence.Smallest trigger, compiled with WABT 1.0.42
wat2wasm --enable-all:U+0000 is valid UTF-8 and WABT reads section names through
ReadStr, which only checks UTF-8, sowasm-validate --enable-allaccepts the module. Expected: Evidence whose custom section description is the text objdump displayed,"visible".Change and scope
parseWabtOutputcompares each custom-section row with the decoded name up to its first NUL, as it already does formodule name:preamble lines. The sectiondescriptionstays 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
src/wasm/WabtOutput.ts.docs/public/product-catalog.json), package, or installation impact: none.Evidence and regression coverage
src/wasm/WabtOutput.test.tsframes the real objdump golden with the decoded nametest\0hidden(description"test") and still rejectsother\0test. The real-tool fixturetests/fixtures/wasm/custom-names.watgainsvisible\00hidden, andscripts/verify-wasm-artifact.mjsexpects its"visible"description through CLI and MCP.binary-reader-objdump.cc(BeginCustomSection),wat-writer.cc(WriteQuotedDataescapes byte 0 as\00),wast-parser.cc(ParseQuotedText),binary-reader.cc(ReadStr) andutf8.cc(IsValidUtf8). The first assertion of the new unit test throws on the base revision.unreadable_outputwith reasonWABT custom-section header does not match decoded WAT.; after, Evidence with the custom section description"visible".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:
Validation performed
Compatibility, safety, and release
Review checklist
type(scope): outcome.