Repository navigation
feat(erlang): inspect BEAM IFF chunks and tables - #4833
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. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The PR appears safe to merge; the latest change addresses the previous input-policy finding. SummaryAdds
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[CLI or MCP] --> B[BeamService checks input]
B --> C[BeamProvider reads a stable file]
C --> D[BeamParser checks bounds and budgets]
D --> E[Chunks and decoded tables]
E --> F[BeamService returns Evidence]
Reviews (7) · Last reviewed commit: "fix(erlang): use publicInputStrictObject..." · Reviewed by Greptile |
CassieFox23
left a comment
There was a problem hiding this comment.
TL;DR: I checked the 4 open Greptile threads against c9d1532. Three bugs reproduce. Table rows have no cap. A truncated chunk header passes. And bad UTF-8 in atom names turns into a replacement character. The fourth thread is right too: the tests have no real compiled BEAM file. A hand-built OTP 28 atom table also fails to parse.
I only ran small files I made myself and the 8 test files this PR touches. The 8 test files all pass on Node 24.
Findings and verdicts
Head c9d1532. "Reproduces" means a file I built byte by byte shows the bug through the same service the CLI and MCP tool use.
| # | Thread | Sev | Verdict | What I saw |
|---|---|---|---|---|
| 1 | Tables can exhaust memory | P1 | Reproduces | A 66,000,024-byte file with 5,500,000 ExpT rows is under the 64 MiB limit. It parsed with no error, took about 15 seconds and about 2.1 GB of memory. With a 512 MB heap, Node crashed with out of memory. 5,000 atoms get a clean limit error. Rows get none |
| 2 | Truncated headers pass | P2 | Reproduces | The 16-byte file FOR1, size 8, BEAM, four zero bytes returns chunks: [] with complete coverage. The CLI (inspect-erlang-beam) exits 0 on it |
| 3 | Invalid atom bytes change silently | P2 | Reproduces | Atom bytes ff give the name U+FFFD and the same module. A fatal UTF-8 decoder throws on the same byte |
| 4 | Tests lack real BEAM files | P2 | Accurate | No .beam file is in the tree. The tests only use the hand-built fixture. See the OTP 28 note below |
OTP 28 note for row 4. In beam_asm.erl on OTP master, build_atom_table has the comment "Build an atom table for Erlang/OTP 28 and later". It writes the AtU8 count as a negative number, and each atom length with encode(?tag_u, Len). The tag u is number 0 in beam_makeops, so for a short atom the length byte is the length shifted left by 4. This parser reads a plain positive count and a plain one-byte length. I built one atom a in the OTP 28 layout by hand (FFFFFFFF 10 61). The parser rejects it with "BEAM atom table exceeds the 4096-atom budget". The CLI exits 1 with that message and tells the user to raise max_atoms, which would not help. The older layout matches the parser. I could not build a real file, since there is no erlc on my box. So please treat this as a lead. A compiler-built fixture would settle it.
For row 1, I only timed the service. I did not run the CLI or MCP path end to end. The default heap on my box coped with 66 MB. A smaller heap or a larger max_file_bytes would not.
Test results, 8 test files this PR touches:
| Node | Result |
|---|---|
| 24.18.0 | 27 tests passed in 8 files |
Not run
- A compiler-built BEAM file. There is no
erlcon my box. - The CLI and MCP path end to end on the 66 MB file, and files over 64 MiB.
- Node 22 and Node 26.
- I skipped the resolved Malayalam thread. I did not retest
scripts/website.py check. - The full suite, typecheck and lint. Only named test files ran.
- Main at d6ca7b3. I tested the head only.
Thanks, mvanhorn, for the work on this.
Test setup
Commands
npm ci --ignore-scripts; npm run build:cached; npm run test:prepare (Node 24, tree at c9d15327c)
npm run test:focused -- <my probe file> (7 cases, files built by a script)
systemd-run --user --scope -p MemoryMax=4G -- /usr/bin/time -v npm run test:focused -- <my rows probe>
the same with NODE_OPTIONS=--max-old-space-size=512
npm run test:focused -- <the 8 touched test files>
node scripts/rea.mjs inspect-erlang-beam <file> --json (CLI check of rows 2 and 4)
The 8 files: src/application/erlang/BeamService.test.ts, src/domain/erlang/beam.test.ts, src/erlang/BeamParser.test.ts, src/contracts/toolEffects.test.ts, tests/acceptance/erlangBeamCli.test.ts, tests/acceptance/tools/localToolContracts.test.ts, tests/boundary/filesystem/erlangBeam.test.ts, tests/boundary/mcp/erlangBeamMcp.test.ts.
None of them mentions doctor. I checked with grep first.
Fixture bytes (hex of the OTP 28 file, 28 bytes): 464f5231 00000014 4245414d 41745538 00000006 ffffffff 1061 0000.
The other fixtures: row 1 is FOR1, form size, BEAM, one ExpT chunk with count 5,500,000 and 12 zero bytes per row. Row 2 is 16 bytes: FOR1, size 8, BEAM, four zero bytes. Row 3 is one AtU8 chunk with payload 00 00 00 01 01 ff.
🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊
|
Thanks. dd22424 caps export, import and lambda rows at 65536 combined before any row is allocated, rejects a form remainder shorter than a chunk header, and rejects AtU8 names that are not valid UTF-8. On the OTP 28 lead: the parser now reads the compact AtU8 layout (negated count, u-tag name lengths). There is also a compiler-produced OTP 29 BEAM fixture whose expected atoms, table rows and Code header come from beam_lib on the same file. I also merged current main; format, lint, typecheck, build and the focused BEAM tests pass locally. |
4113431 to
94f95a6
Compare
|
Restacked onto current main and kept the BEAM IFF workflow. Tip:
This token cannot update |
|
Restack is ready, but this token cannot update Force-with-lease from
The only workflow file that differs from the fork tip is Ready tip: Fetch it from A credential that may update workflow files on the fork can move the existing PR with: On that tip, |
Replay the Erlang BEAM inspection workflow, including table bounds, OTP 28+ atom layouts, the shared absolute-path policy, and empty-path CLI coverage, without carrying GitHub workflow edits. Co-authored-by: morluto <morluto@users.noreply.github.com>
bf9c4c8 to
3714cdd
Compare
inspect_erlang_beam advertised a public input built with bare z.strictObject, so later shared input-policy changes would miss it. Result and internal objects stay on their own constructors. Co-authored-by: morluto <morluto@users.noreply.github.com>
Summary
Add
inspect_erlang_beam/inspect-erlang-beamfor one explicit localFOR1/BEAMIFF file. The workflow returns chunk names and payload SHA-256,Atom/AtU8 names, export/import/lambda tables with resolved atom names when
present, and the Code chunk instruction-set header.
It does not execute bytecode or require an Erlang installation. Missing optional
tables stay null. Malformed FOR1/BEAM headers, truncated chunks, and exhausted
budgets fail without partial success. LitT inflation and Attr/CInf external-term
decoding remain out of scope.
Usage
MCP:
inspect_erlang_beamwith an absolutepath.Tests
npm run check:fastnpm run test:local --domain, parser, and service tests (8 passed)npm run test:focused --CLI, MCP, and filesystem tests (7 passed)Demo