Skip to content

feat(elf): inspect PT_NOTE and SHT_NOTE tables - #4837

Merged
gensokyo-dev merged 15 commits into
morluto:mainfrom
mvanhorn:fix/elf-notes
Oct 22, 2026
Merged

gensokyo-dev merged 15 commits into
morluto:mainfrom
mvanhorn:fix/elf-notes

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add inspect_elf_notes / inspect-elf-notes for one explicit local ELF32/ELF64
image. The workflow reads PT_NOTE program headers and SHT_NOTE sections
independently and returns owners, types, descriptor SHA-256, and GNU build-id,
ABI-tag, and gold-version fields when those descriptors match.

It does not execute the image or consult a package catalog. The same file range
may appear twice when both tables declare it. A missing table list is observed
absence of those declarations. Malformed ELF headers, truncated notes, and
exhausted budgets fail without partial success. ELF extended numbering is
unsupported.

Note name and descriptor padding follows the containing table's alignment
(4 or 8, with 0/1 treated as 4), measured from the start of each note, so
8-aligned .note.gnu.property entries in ordinary GNU/Linux binaries parse.

Usage

rea inspect-elf-notes /absolute/path/to/program --json

MCP: inspect_elf_notes with an absolute path.

Tests

  • npm run check:fast
  • npm run test:local -- domain, parser, and service tests, including 8-aligned PT_NOTE and SHT_NOTE fixtures (18 passed)
  • npm run test:focused -- CLI, MCP, and filesystem tests (7 passed)
  • Parsed /bin/ls, /usr/bin/env, and a gcc -Wl,--build-id binary: GNU property, build-id, and ABI-tag notes listed in both tables

Demo

demo

Author readiness

Human owner: @mvanhorn

  • 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.

Add inspect_elf_notes for ELF32/ELF64 note program headers and
sections, including GNU build-id, ABI-tag, and gold-version fields.
The workflow reads a stable image without executing it or consulting
a package catalog.
GNU property notes in 8-byte-aligned PT_NOTE and SHT_NOTE tables pad
from the start of each note, matching readelf. Independently rounding
namesz and descsz treated a 48-byte .note.gnu.property as truncated.
Treat declared alignment 0 or 1 as 4.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 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 ⚠️ Failed 2026-10-22T06:29:08.619966Z
We couldn’t complete this review. Comment @codex review to try again.
36f19ae Manual request
ℹ️ 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

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge; no new blocking issue was found.

Summary

Adds inspect_elf_notes and inspect-elf-notes for static inspection of one selected ELF file.

  • ELF note reports show declared tables and matching GNU fields.
  • CLI and MCP callers can inspect a selected ELF file’s note tables.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  CLI["CLI: resolve selected path"] --> Service["ElfNotesService: check input"]
  MCP["MCP: inspect_elf_notes"] --> Service
  Service --> Read["Read one stable regular file"]
  Read --> Parse["Parse PT_NOTE and SHT_NOTE within budgets"]
  Parse --> Evidence["Check result and create evidence"]
  Evidence --> CLIResult["CLI JSON"]
  Evidence --> MCPResult["MCP reply size check"]
Loading

Reviews (8) · Last reviewed commit: "chore(elf): preserve both diagnostics wo..." · Reviewed by Greptile

Comment thread src/native/elf/ElfNoteParser.ts Resolved
Comment thread src/native/elf/ElfNoteParser.ts Resolved
Comment thread src/native/elf/ElfNoteParser.ts Resolved
Comment thread src/native/elf/ElfNoteParser.ts Resolved

@CassieFox23 CassieFox23 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TL;DR: The PR's tests pass on Node 22, 24 and 26, with clean typecheck. But all four Greptile P1 findings in ElfNoteParser.ts are real, shown with small ELF files I built. Two give a false "complete", one blocks for seconds, and one holds 5.6 GiB.

Edit: The head moved to e3adf57, and the four findings below are fixed there. I retested, and the two new Greptile threads are real; the results are here.

On 2026-10-18 the head is still 325de37. Five Greptile threads are still open. No replies.

Results

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
Typecheck (tsc --noEmit) at head 325de37 pass pass pass
Typecheck at merge base af67ad5 pass pass pass
The PR's 8 test files at head, 37 tests 37 pass 37 pass 37 pass
The 2 PR-changed test files that exist at af67ad5, 12 tests 12 pass 12 pass 12 pass

The other 6 test files are new in this PR, so they have no base run. I read the test names in ElfNoteParser.test.ts. I searched for extended numbering. I found no test for the four cases below.

Findings

1. One ELF exhausts memory (line 168): confirmed. 62,916,428-byte file fits 64 MiB default. parseElfNotes held 5,761 MiB (5.63 GiB). That is 96 times the file.

2. GNU version freezes requests (line 217): confirmed. NUL bytes before "x" in GNU type-4 note cause quadratic regex time. 131,072 NULs took 9,168 ms on Node 24.

3. Truncated headers pass (line 252): confirmed. A 68-byte ELF64 with truncated PT_LOAD returns complete. No tables appear. readelf reports an error.

4. Extended section counts are lost (line 254): confirmed. A 232-byte ELF64 with e_shnum 0 returns complete. The real count is 2 in section 0. readelf shows "Number of section headers: 0 (2)".

Not run

  • The Greptile P2 at ElfNotesService.ts:107, a duplicate machine mapping. It is outside the four P1s.
  • Memory case through MCP server or CLI. Did not check MCP reply limit after parsing.
  • The fixes Greptile suggests. I did not apply or test them.
  • Full test suite and other CI jobs (lint, docs, module boundaries). Only PR's test files ran.
  • Four cases as ELF32 or big-endian files.
  • Timing on shared box; milliseconds rough. The 4 times per doubling is useful.

Thanks, mvanhorn, for the PR and its tests. They ran clean on all three Nodes.

Finding 1 detail

One file of 62,916,428 bytes fits the 64 MiB default (67,108,864). It has 32 PT_NOTE headers, which is the default entry budget. All of them point at one note with a 60 MiB name. parseElfNotes returned holding 5,761 MiB (5.63 GiB) more process memory than before. That is 96 times the file, and the ratio was the same at 4, 8 and 16 MiB. This ran in process on Node 24 only.

Finding 2 detail

A GNU type-4 note whose descriptor is NUL bytes and then an "x" makes the regex take quadratic time.

NUL bytes before the x 16,384 32,768 65,536 131,072
parseElfNotes, Node 24 141 ms 563 ms 2,235 ms 9,168 ms

Each doubling costs about 4 times. The same bytes in the other order (x, then NULs) take 0.2 to 0.4 ms. At 131,072 NULs Node 22 took 9,010 ms and Node 26 took 9,855 ms. Through the CLI, a 32 KiB file took 1.42 s against 0.79 s for a same-size control (one run each). The call is synchronous. Nothing else in that process can run meanwhile. That is my reading of the code, not measured in the server. A 1 MiB run would take about 10 minutes (an estimate from the 4 times per doubling, not run).

Finding 3 detail

The file is a 68-byte ELF64 with phoff 64, phentsize 56, phnum 1, and PT_LOAD in the last four bytes. The parser returns complete. The CLI returns complete too. No tables appear. The CLI exits 0. readelf says: "Error: Reading 56 bytes extends past end of file for program headers". With PT_NOTE in those four bytes, the parser fails. It says "ELF range 72 + 8 leaves the artifact". Only non-note entries slip through.

Finding 4 detail

The file is a 232-byte ELF64 with e_shoff 104, e_shnum 0, and the real count (2) in section 0. Section 1 is an SHT_NOTE holding a GNU build-id. readelf prints "Number of section headers: 0 (2)" and lists the build-id. REA returns complete. No tables appear. REA prints No PT_NOTE program header or SHT_NOTE section was declared. as its message. With e_shnum 2, the same ELF gives 1 table and 1 entry. docs/elf-notes.md says extended numbering is unsupported. So this file should fail, not pass.

Test notes

I read the test names in ElfNoteParser.test.ts. I searched for extended numbering. I found no test for the four cases below.

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 / base: 325de37 / af67ad5 (the merge base with main)
  • Other: GNU readelf 2.46.1-1.fc44 (binutils, GPL-3.0-or-later); load average 4.29 / 3.88 / 2.59 over 1, 5 and 15 minutes on 24 threads, read right after the runs, with a local model server and the desktop running
Commands
# trees, from a read-only mirror of this repo
git -C ~/code/rea-mirror/rea.git archive refs/pull/4837/head | tar -x -C /tmp/pr4837/src
git -C ~/code/rea-mirror/rea.git archive af67ad50477fa0bd991f58149f381de6b36090f2 | tar -x -C /tmp/pr4837/base
# in each tree, Node 24
npm ci --ignore-scripts
npm run build:cached            # head only; the test runner builds base itself

# once per Node (22, 24, 26), in each tree
node node_modules/typescript/bin/tsc --noEmit
node scripts/run-development-tests.mjs focused \
  src/application/binaryDiagnostics/ElfNotesService.test.ts src/contracts/toolEffects.test.ts \
  src/domain/native/elfNotes.test.ts src/native/elf/ElfNoteParser.test.ts \
  tests/acceptance/elfNotesCli.test.ts tests/acceptance/tools/localToolContracts.test.ts \
  tests/boundary/filesystem/elfNotes.test.ts tests/boundary/mcp/elfNotesMcp.test.ts
# base: only src/contracts/toolEffects.test.ts and tests/acceptance/tools/localToolContracts.test.ts exist

# cross-checks
readelf -h -l trunc68.elf
readelf -h -S -n extshnum.elf
readelf -n redos32k.elf
node scripts/rea.mjs inspect-elf-notes trunc68.elf --json     # also extshnum.elf, redos32k.elf
node --expose-gc mem.mjs 60 32                                 # name MiB, header count
Crafted ELF builders (Node, all little-endian ELF64)
const ehdr64 = ({ phoff = 0, shoff = 0, phnum = 0, shnum = 0, shstrndx = 0, phentsize = 56, shentsize = 64 } = {}) => {
  const b = Buffer.alloc(64);
  b.write("\x7fELF", 0, "latin1"); b[4] = 2; b[5] = 1; b[6] = 1;
  b.writeUInt16LE(2, 16); b.writeUInt16LE(62, 18); b.writeUInt32LE(1, 20);
  b.writeBigUInt64LE(BigInt(phoff), 32); b.writeBigUInt64LE(BigInt(shoff), 40);
  b.writeUInt16LE(64, 52); b.writeUInt16LE(phentsize, 54); b.writeUInt16LE(phnum, 56);
  b.writeUInt16LE(shentsize, 58); b.writeUInt16LE(shnum, 60); b.writeUInt16LE(shstrndx, 62);
  return b;
};
const phdr64 = ({ type, offset = 0, filesz = 0, align = 4 }) => {
  const b = Buffer.alloc(56);
  b.writeUInt32LE(type, 0); b.writeBigUInt64LE(BigInt(offset), 8);
  b.writeBigUInt64LE(BigInt(filesz), 32); b.writeBigUInt64LE(BigInt(align), 48);
  return b;
};
const shdr64 = ({ type = 0, offset = 0, size = 0, align = 0 }) => {
  const b = Buffer.alloc(64);
  b.writeUInt32LE(type, 4); b.writeBigUInt64LE(BigInt(offset), 24);
  b.writeBigUInt64LE(BigInt(size), 32); b.writeBigUInt64LE(BigInt(align), 48);
  return b;
};
const note = (name, type, desc) => {
  const n = Buffer.concat([Buffer.from(name, "latin1"), Buffer.alloc(1)]);
  const h = Buffer.alloc(12);
  h.writeUInt32LE(n.length, 0); h.writeUInt32LE(desc.length, 4); h.writeUInt32LE(type, 8);
  const pad = (len) => Buffer.alloc((4 - (len % 4)) % 4);
  return Buffer.concat([h, n, pad(n.length), desc, pad(desc.length)]);
};
const buildId = note("GNU", 3, Buffer.from("0123456789abcdef0123456789abcdef01234567", "hex"));

// 3: truncated header table (68 bytes)
const trunc68 = Buffer.concat([ehdr64({ phoff: 64, phnum: 1 }), Buffer.from([1, 0, 0, 0])]);

// 4: extended section count (232 bytes); the control uses ehdr64 shnum 2 and shdr64 size 0
const body = Buffer.concat([buildId, Buffer.alloc(104 - 64 - buildId.length)]);
const sec1 = shdr64({ type: 7, offset: 64, size: buildId.length, align: 4 });
const extshnum = Buffer.concat([ehdr64({ shoff: 104, shnum: 0 }), body, shdr64({ size: 2 }), sec1]);

// 2: NULs then x in a GNU type-4 note
const gold = (desc) => {
  const n = note("GNU", 4, desc);
  return Buffer.concat([ehdr64({ phoff: 64, phnum: 1 }), phdr64({ type: 4, offset: 120, filesz: n.length }), n]);
};
const redos = gold(Buffer.concat([Buffer.alloc(32768), Buffer.from("x")]));

// 1: 32 PT_NOTE headers share one note whose name is 60 MiB of "A"
const nameLen = 60 * 1048576, count = 32;
const head = Buffer.alloc(12); head.writeUInt32LE(nameLen, 0);
const noteBody = Buffer.concat([head, Buffer.alloc(nameLen, 0x41)]);
const off = 64 + 56 * count;
const mem = Buffer.concat([
  ehdr64({ phoff: 64, phnum: count }),
  ...Array.from({ length: count }, () => phdr64({ type: 4, offset: off, filesz: noteBody.length })),
  noteBody,
]);

Each buffer goes to parseElfNotes(bytes, { path, sha256, bytes: bytes.length }, input) from the built dist/native/elf/ElfNoteParser.js, with input from inspectElfNotesInputSchema.parse({ path }), so the defaults of 32 entries and 64 MiB apply.

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

- Share one byte budget across note sections
- Scan backward for the NUL terminator instead of a quadratic regex
- Range-check the full program and section header tables
- Reject extended section counts
- Reuse elfArchitecture from elfFixedHeader in ElfNotesService
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Addressed all five in da5d634:

  1. Note sections now share one byte budget instead of each getting its own.
  2. The NUL terminator is found with a backward scan, replacing the quadratic regex.
  3. The program and section header tables are range-checked in full before any entry is read.
  4. Extended section counts (e_shnum 0 with the real count in section 0) are rejected.
  5. ElfNotesService reuses elfArchitecture from elfFixedHeader instead of its own mapping.

I also merged main (e289d01) and mirrored the ELF notes README row into the translated READMEs (e3adf57), which clears the documentation facts and translated README checks.

Comment thread src/native/elf/ElfNoteParser.ts Resolved
Comment thread src/native/elf/ElfNoteParser.test.ts Resolved

@CassieFox23 CassieFox23 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TL;DR: The four problems from my earlier review are fixed in da5d634; I checked each with the same small ELF files. Still broken: Greptile's new P1 is real. The cause: 60,000 empty note sections share one unterminated 60 MiB name. That made the parser run 95 to 112 seconds and return complete. Greptile's new P2 is real too: the host-ELF test fails on a binary with no notes.

Edit: I retested on 43974ac. Both problems here are fixed, and Greptile's new P1 shows up as a slowdown; the results are here.

Results

On head e3adf57, base b0b485a. Node 24 only for the memory case.

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
Typecheck (tsc --noEmit) pass pass pass
The PR's 8 test files, 41 tests 41 pass 41 pass 41 pass
Earlier #3: 68-byte ELF64, header table cut off rejected rejected rejected
Earlier #4: 232-byte ELF64, real section count in section 0 rejected rejected rejected
Earlier #2: 131,072 NULs then x, parse time 1.2 ms 0.9 ms 0.8 ms
Earlier #1: 60 MiB name x 32 PT_NOTE headers not run rejected in 3.2 ms not run
New P1: 60,000 empty SHT_NOTE sections, one 60 MiB name with no NUL 97,834 ms, complete 112,242 ms, complete 95,421 ms, complete

For comparison, the older parser from 325de37 took 9,126 ms on the 131,072-NUL file. It kept 5,760 MiB more memory on the 60 MiB file (Node 24). Those match my earlier numbers (9,168 ms and 5,761 MiB). The 68-byte and 232-byte files now fail. Their messages are:

  • ELF range 64 + 56 leaves the artifact.
  • ELF extended numbering is unsupported.

The CLI exits 1 for both. The controls (a full header, and the same ELF with e_shnum 2) still pass.

New findings

P1, "Section names block requests" (ElfNoteParser.ts:124): confirmed. The file is 66,754,752 bytes, under the 64 MiB default. It has 60,000 empty SHT_NOTE sections. All of them point at one 60 MiB name table with no NUL byte. parseElfNotes returned complete with 60,000 tables after 95 to 112 seconds. The same layout with one NUL at the end is rejected by the byte budget in 1.1 ms, so the missing NUL is the cause. Time grows with the section count (12.9, 24.4 and 46 ms at 1,000, 2,000 and 4,000 sections, 1 MiB name). Through the CLI, 20,000 sections with a 20 MiB name took 4.8 s, against 0.8 s for the NUL version. That the call blocks the server comes from my reading of ElfNotesProvider.ts line 68. That line calls the parser directly, with no worker. I did not measure it in the server.

P2, "Host test requires notes" (ElfNoteParser.test.ts:257): confirmed. I removed the note sections from a copy of the host ls. The copy is GNU coreutils 9.10, under GPL-3.0-or-later AND GFDL-1.3-no-invariants-or-later AND LGPL-2.1-or-later AND LGPL-3.0-or-later. The parser returned complete with 0 entries, which is correct. A copy of the PR's test file pointed at that binary failed: expected [] to include 'gnu_property'. On this box the real ls has notes, so the real test passes.

CI note (secondhand, from the job logs): Test shard 3/5 and Portable tests fail on one test, cutterDescriptorLifetime. The PR does not touch that file. I did not run it.

Not run

  • The earlier four cases and the new P1 on the base b0b485a.
  • The memory case through the CLI or MCP server, and the new P1 at full size through the CLI (the CLI run used 20,000 sections).
  • Greptile's fix for the new P1. I did not apply or test it.
  • ELF32 and big-endian forms of any case.
  • Full test suites, lint, docs build and the CI jobs. Only the PR's 8 test files ran.

Thanks, mvanhorn, for the quick fix. The four earlier cases are now handled, and the PR's 41 tests ran clean on all three Nodes.

Raw numbers
Case Result
131,072 NULs then x, older parser, Node 24 9,125.7 ms
131,072 NULs then x, new parser, Node 22 / 24 / 26 1.2 / 0.9 / 0.8 ms
1,048,576 NULs then x, new parser, Node 22 / 24 / 26 1.9 / 1.6 / 1.4 ms
60 MiB name x 32 headers, older parser, Node 24 memory use 127 to 5,887 MiB
4, 8, 16, 60 MiB name x 32 headers, new parser, Node 24 rejected, 0.8 to 3.2 ms
Sections with no NUL, 1 MiB name, 1,000 / 2,000 / 4,000 sections 12.9 / 24.4 / 46 ms
Sections with no NUL, 4 MiB name, 2,000 sections 78.2 ms
Same layout, one NUL at the end, 2,000 sections rejected in 1.1 ms

The older parser is the file from 325de37. It was compiled with esbuild and run against the new head's built files. Timing runs were on a shared box.

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 / base: e3adf57 / b0b485a (GitHub's base for the PR; main is now at 32f0e51)
  • Other: GNU readelf 2.46.1-1.fc44 (binutils, GPL-3.0-or-later); load average about 4 on 24 threads during the long runs, with a local model server and the desktop running
Commands
# tree, from a read-only mirror of this repo
git -C ~/code/rea-mirror/rea.git archive e3adf57f46deecf3849c771aac7049784de45c55 | tar -x -C /tmp/ev-4837/head
# Node 24
npm --prefix /tmp/ev-4837/head ci --ignore-scripts
npm --prefix /tmp/ev-4837/head run build:cached

# once per Node (22, 24, 26)
env -C /tmp/ev-4837/head node node_modules/typescript/bin/tsc --noEmit
env -C /tmp/ev-4837/head node scripts/run-development-tests.mjs focused \
  src/application/binaryDiagnostics/ElfNotesService.test.ts src/contracts/toolEffects.test.ts \
  src/domain/native/elfNotes.test.ts src/native/elf/ElfNoteParser.test.ts \
  tests/acceptance/elfNotesCli.test.ts tests/acceptance/tools/localToolContracts.test.ts \
  tests/boundary/filesystem/elfNotes.test.ts tests/boundary/mcp/elfNotesMcp.test.ts

# repros: each builder below writes a Buffer, parsed with parseElfNotes from the built dist
# new P1, 60,000 sections, 60 MiB name, no NUL:  secNames(60000, 62914560)
# control, one NUL at the end:                    secNames(2000, 1048576, true)
node --expose-gc run.mjs /tmp/ev-4837/head/dist mem 60 32

# cross-checks
readelf -h -S -n extshnum.elf
node scripts/rea.mjs inspect-elf-notes sec20k.elf --json
objcopy --remove-section='.note*' /usr/bin/ls ls-nonotes
Crafted ELF builders (Node, all little-endian ELF64)
const ehdr64 = ({ phoff = 0, shoff = 0, phnum = 0, shnum = 0, shstrndx = 0, phentsize = 56, shentsize = 64 } = {}) => {
  const b = Buffer.alloc(64);
  b.write("\x7fELF", 0, "latin1"); b[4] = 2; b[5] = 1; b[6] = 1;
  b.writeUInt16LE(2, 16); b.writeUInt16LE(62, 18); b.writeUInt32LE(1, 20);
  b.writeBigUInt64LE(BigInt(phoff), 32); b.writeBigUInt64LE(BigInt(shoff), 40);
  b.writeUInt16LE(64, 52); b.writeUInt16LE(phentsize, 54); b.writeUInt16LE(phnum, 56);
  b.writeUInt16LE(shentsize, 58); b.writeUInt16LE(shnum, 60); b.writeUInt16LE(shstrndx, 62);
  return b;
};
const shdr64 = ({ name = 0, type = 0, offset = 0, size = 0, align = 0 }) => {
  const b = Buffer.alloc(64);
  b.writeUInt32LE(name, 0); b.writeUInt32LE(type, 4); b.writeBigUInt64LE(BigInt(offset), 24);
  b.writeBigUInt64LE(BigInt(size), 32); b.writeBigUInt64LE(BigInt(align), 48);
  return b;
};

// new P1: K empty SHT_NOTE sections, all with sh_name 0, over one string table.
// terminated=false: the table has no NUL at all. terminated=true: one NUL at the very end.
const secNames = (K, nameBytes, terminated = false) => {
  const shnum = K + 2;
  const tabOff = 64 + shnum * 64;
  const strtab = Buffer.alloc(nameBytes, 0x41);
  if (terminated) strtab[nameBytes - 1] = 0;
  const hdrs = [shdr64({}), shdr64({ type: 3, offset: tabOff, size: nameBytes })];
  const noteHdr = shdr64({ type: 7, offset: tabOff, size: 0, align: 4 });
  const noteList = Array.from({ length: K }, () => noteHdr);
  return Buffer.concat([ehdr64({ shoff: 64, shnum, shstrndx: 1 }), ...hdrs, ...noteList, strtab]);
};

The 68-byte, 232-byte, NUL-then-x and 60 MiB-name builders are unchanged. They are the ones in my earlier review. Each buffer goes to parseElfNotes(bytes, { path, sha256, bytes: bytes.length }, input) from the built dist/native/elf/ElfNoteParser.js, with input from inspectElfNotesInputSchema.parse({ path }), so the defaults of 32 entries and 64 MiB apply.

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

cString returned before charging the text budget when a section name had
no NUL, so many empty SHT_NOTE sections pointing at one unterminated name
table rescanned it without limit. The scan now stops at the remaining
budget, and a failed lookup is charged for the bytes it read.

The host ELF test no longer assumes the probed binary has notes. It still
checks the build-id and ABI-tag fields when those entries are present.
main moved 236 commits past this branch. Conflicts and resolutions:

- README.md, docs/index.md and the ko, ru, vi and zh READMEs: main
  added rows (IL2CPP, Godot PCK, desktop installations and others)
  next to the ELF notes row this branch adds. Kept main's tables and
  re-added the ELF notes row and guide link.
- src/application/CapabilityInventory.ts: main reworked the EVM
  interface check to report limiter availability. Kept main's EVM
  block and this branch's inspect_elf_notes entry before it.
- src/contracts/toolEffects.test.ts: kept both the ELF notes and the
  new desktop application effect expectations.
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks for the repro. In 0151a3f cString stops at the remaining text budget, and a failed lookup with no NUL is now charged for the bytes it read, so repeated empty SHT_NOTE sections pointing at one unterminated name table can no longer rescan it for free. The host ELF test no longer requires notes; it still checks build-id and ABI-tag fields when they are present. I also merged current main; format, lint, typecheck, build and the focused ELF notes tests pass locally.

Comment thread src/native/elf/ElfNoteParser.ts Resolved
@CassieFox23

CassieFox23 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: Both problems from my last review are fixed on 43974ac, and the four older ones still hold. Greptile's new P1, "Repeated payloads block requests", is real. One 60 MiB note payload shared by 32 PT_NOTE headers parses as complete in about 0.9 s. It does that because the payload is hashed again for every header. None of that work counts against the byte budget.

Edit (21 Oct): Greptile's P1 is fixed on 9b9d446. See the retest.

Results

On head 43974ac, base 9258df0. The new P1 rows were measured in process, with parseElfNotes called on crafted ELF64 files. The host-ELF test copy ran on Node 24 only.

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
The PR's 8 test files, 42 tests 42 pass 42 pass 42 pass
My e3adf57 P1: 60,000 empty SHT_NOTE sections, one 60 MiB name with no NUL rejected, 2.9 ms rejected, 6.5 ms rejected, 3.8 ms
My e3adf57 P2: host-ELF test on a copy of ls with the notes removed not run 18 pass, parser says complete, 0 entries not run
Earlier #3: 68-byte ELF64, header table cut off rejected rejected rejected
Earlier #4: 232-byte ELF64, real section count in section 0 rejected rejected rejected
Earlier #2: 131,072 NULs then x, parse time 1.9 ms 1.3 ms 1.4 ms
Earlier #1: 60 MiB name x 32 PT_NOTE headers rejected, 3.4 ms rejected, 2.5 ms rejected, 2.4 ms
New P1: 60 MiB descriptor x 32 PT_NOTE headers, owner not GNU complete, 864 ms complete, 856 ms complete, 887 ms
New P1: same, all-zero GNU type-4 descriptor complete, 1,961 ms complete, 1,811 ms complete, 1,797 ms

At e3adf57 the 60,000-section file came back complete after 95 to 112 seconds (my last review). Now it is rejected with ELF note text exceeds the 66754752-byte budget. The two older messages still read ELF range 64 + 56 leaves the artifact. and ELF extended numbering is unsupported. The CLI exits 1 for both.

New finding

P1, Repeated payloads block requests (ElfNoteParser.ts:418): reproduced. toEntry calls sha256(note.descriptor) once per header. The shared text budget does not count that work. I built one note with a 60 MiB descriptor and pointed 32 PT_NOTE headers at it. The file is 62,916,432 bytes, under the 64 MiB default, and the parse returned complete with 32 entries.

Headers sharing the 60 MiB descriptor (Node 24) 1 8 32
Owner not GNU (hashing only) 27.6 ms 214.7 ms 856.1 ms
All-zero GNU type-4 descriptor (hashing plus the trailing-NUL scan) 57.2 ms 450.1 ms 1,810.7 ms

The time grows in step with the header count. Hashing a 60 MiB buffer 32 times with plain createHash, no ELF code, took 846.5 ms. So hashing is nearly all of the first row. The 32 x 60 MiB is 1.875 GiB, which matches Greptile's "about 1.9 GiB".

At the schema ceilings (max_file_bytes 536,870,912 and max_entries 256), 256 headers sharing a 500 MiB descriptor took 58.2 seconds. The file was 524,302,416 bytes and the parse returned complete with 256 entries. That is 125 GiB of hashing, the figure Greptile gave. Through the CLI, the 32-header file took 2.09 s wall against 1.02 s for one header.

That this blocks other MCP requests comes from my reading of ElfNotesProvider.inspect. It calls parseElfNotes directly in the async handler, with no worker. I did not measure it inside a running server. At the defaults the stall is about 1 to 2 seconds. The long cases need the caller to raise both limits.

Not run

  • The base 9258df0 and e3adf57: not rebuilt. The e3adf57 numbers come from my last review.
  • The host-ELF test copy on Node 22 and 26.
  • The all-zero GNU type-4 case at the 500 MiB x 256 size.
  • The new P1 inside a running MCP server, and Greptile's fix (not applied).
  • ELF32 and big-endian forms of any case.
  • Full test suites, lint, docs build and the CI jobs. Only the PR's 8 test files ran.

Thanks, mvanhorn, for the quick fix on the section names and the host test. Both are handled, and the PR's 42 tests ran clean on all three Nodes.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.11
  • 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 / base: 43974ac / 9258df0 (GitHub's base for the PR; main is now at d0067ba)
  • Other: GNU binutils objcopy and readelf (Fedora 44 package) to strip notes from a copy of ls. The box was shared: load average about 4.7 on 24 threads during the runs.
Commands
# tree, from a read-only mirror of this repo
git -C ~/code/rea-mirror/rea.git archive 43974ac745fd3e30e076d4c94d76dd89f3390e1c | tar -x -C /tmp/b6-mv2/h4837
# Node 24
npm --prefix /tmp/b6-mv2/h4837 ci --ignore-scripts
npm --prefix /tmp/b6-mv2/h4837 run build:cached
npm --prefix /tmp/b6-mv2/h4837 run test:prepare

# once per Node (22, 24, 26)
npm --prefix /tmp/b6-mv2/h4837 run test:focused -- \
  src/application/binaryDiagnostics/ElfNotesService.test.ts src/contracts/toolEffects.test.ts \
  src/domain/native/elfNotes.test.ts src/native/elf/ElfNoteParser.test.ts \
  tests/acceptance/elfNotesCli.test.ts tests/acceptance/tools/localToolContracts.test.ts \
  tests/boundary/filesystem/elfNotes.test.ts tests/boundary/mcp/elfNotesMcp.test.ts

# host-ELF test: strip the notes from a copy of ls, point a copy of the test file at it, run it (Node 24)
objcopy --remove-section='.note*' /usr/bin/ls /tmp/b6-mv2/probes/ls-nonotes

# probes: each builder writes a Buffer that goes to parseElfNotes from the built dist
node run.mjs /tmp/b6-mv2/h4837/dist sec 60000 62914560     # my e3adf57f4 P1
node run.mjs /tmp/b6-mv2/h4837/dist pay X 60 32            # new P1, owner not GNU
node run.mjs /tmp/b6-mv2/h4837/dist pay GNU4 60 32         # new P1, all-zero GNU type 4
P_MAXFILE=536870912 P_MAXENT=256 node run.mjs /tmp/b6-mv2/h4837/dist pay X 500 256

# CLI
node scripts/rea.mjs inspect-elf-notes pay32.elf --json
Crafted ELF builder for the new P1 (Node, little-endian ELF64)
// count PT_NOTE headers share one note whose descriptor is mib MiB.
// owner "X": not GNU, so the text budget stays near zero. "GNU4": owner GNU, type 4, all-zero descriptor.
const pay = (owner, mib, count) => {
  const desc = Buffer.alloc(mib * 1048576, owner === "GNU4" ? 0 : 0x41);
  const nn = note(owner === "GNU4" ? "GNU" : "X", owner === "GNU4" ? 4 : 1, desc);
  const off = 64 + 56 * count;
  return Buffer.concat([
    ehdr64({ phoff: 64, phnum: count }),
    ...Array.from({ length: count }, () => phdr64({ type: 4, offset: off, filesz: nn.length })),
    nn,
  ]);
};

ehdr64, phdr64 and note are the helpers from my earlier review. Each buffer goes to parseElfNotes(bytes, { path, sha256, bytes: bytes.length }, input) from the built dist/native/elf/ElfNoteParser.js, with input from inspectElfNotesInputSchema.parse({ path }).

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

toEntry hashed a descriptor again for every note header that pointed
at it, and decodeGnu rescanned a GNU version descriptor's trailing NUL
run each time, with neither charged to the note byte budget. One 60 MiB
payload shared by 32 PT_NOTE headers therefore parsed as complete
after about 1.9 GiB of hashing.

Each descriptor range is now hashed once and each GNU version NUL run
scanned once per parse, and repeated headers reuse the result. Bytes
hashed and bytes scanned each count against the same ceiling as note
text, so distinct descriptors cannot exceed it either. A test points
six PT_NOTE headers at one payload and checks they share one hash and
one GNU scan, and that distinct descriptors over the ceiling are
rejected. docs/elf-notes.md describes the new bound.
main moved 77 commits past this branch and added rows (GPU code
objects, PyInstaller and others) to the capability tables, which
oxfmt realigned. Took main's README.md, docs/index.md and
docs/readme/README_zh.md, re-added the ELF notes row and guide link,
and re-ran oxfmt on those files.
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks @CassieFox23 for the measurements on Greptile's "Repeated payloads block requests" P1. Fixed in 9b9d446, which also merges current main. The parser now hashes each descriptor range once and scans each GNU version descriptor's trailing NULs once per parse, and repeated PT_NOTE headers reuse the result. Bytes hashed and bytes scanned are each charged against the same ceiling as note text. A new test points six headers at one payload and checks they share one hash and one GNU scan, and that distinct descriptors over the ceiling are rejected. Format check, lint, typecheck, build and the ElfNoteParser tests pass locally on 9b9d446.

Comment thread src/native/elf/ElfNotesProvider.ts Resolved
Comment thread src/native/elf/ElfNoteParser.ts Resolved
@CassieFox23

CassieFox23 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: The fix for Greptile's P1 works. Before, 32 note headers sharing one 60 MiB payload took 0.86 seconds. Now they take 0.03 seconds. The biggest case allowed fell from 58.2 seconds to 0.23 seconds. The earlier findings and cases still hold, and the PR's 43 tests pass on Node 22, 24 and 26. Greptile's two new P2 threads on 9b9d446 both reproduce.

Edit (21 Oct): Both P2s are fixed on 5d84922. See the retest of the new head.

The head moved to 5d84922 at 7:30 PM EDT while I was writing this up. Everything below was tested on 9b9d446. The two new commits, a1ead5e and 5d84922, target the two new P2s and are not tested yet. I will retest the new head once it sits still.

Results

On head 9b9d446 (the fix is a67c319, then a merge of main), base d8a9673. The "before" figures are from my last retest on 43974ac, same box and same probe script. I did not rebuild 43974ac this time. The probes call parseElfNotes on crafted ELF64 files.

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
The PR's 8 test files (42 tests on 43974ac, plus the new "reuses one descriptor hash" test) 43 pass 43 pass 43 pass
npm run typecheck pass pass pass
P1 fix: 60 MiB descriptor x 32 PT_NOTE headers, owner not GNU (was 864 / 856 / 887 ms) complete, 30.0 ms complete, 31.3 ms complete, 29.8 ms
P1 fix: same, all-zero GNU type-4 descriptor (was 1,961 / 1,811 / 1,797 ms) complete, 65.5 ms complete, 57.0 ms complete, 58.5 ms
My e3adf57 P1: 60,000 empty SHT_NOTE sections, one 60 MiB name rejected, 3.4 ms rejected, 2.7 ms rejected, 2.7 ms
My e3adf57 P2: host-ELF test on a copy of ls with the notes removed 19 pass 19 pass 19 pass
Earlier #3: 68-byte ELF64, header table cut off rejected rejected rejected
Earlier #4: 232-byte ELF64, real section count in section 0 rejected rejected rejected
Earlier #2: 131,072 NULs then x complete, 1.8 ms complete, 1.4 ms complete, 1.5 ms
Earlier #1: 60 MiB name x 32 PT_NOTE headers rejected, 2.9 ms rejected, 2.6 ms rejected, 2.1 ms

The messages did not change. They read ELF note text exceeds the 66754752-byte budget., ELF range 64 + 56 leaves the artifact. and ELF extended numbering is unsupported. The host-ELF test copy now ran on all three Nodes. Last time it ran on Node 24 only.

The P1 fix, in numbers

Time no longer grows with the header count. Node 24, one 60 MiB descriptor:

Headers sharing it 1 8 32
Owner not GNU, before (43974ac) 27.6 ms 214.7 ms 856.1 ms
Owner not GNU, now (9b9d446) 27.8 ms 29.6 ms 31.3 ms
All-zero GNU type 4, before 57.2 ms 450.1 ms 1,810.7 ms
All-zero GNU type 4, now 59.0 ms 57.4 ms 57.0 ms

At the schema ceilings, 256 headers share one 500 MiB descriptor. The ceilings are max_file_bytes 536,870,912 and max_entries 256. That file now takes 234 ms. Before it took 58,202 ms. The all-zero GNU type-4 version takes 465 ms. I did not run that one before. Peak memory is about the same as before (1,566 MiB). Through the CLI, the 32-header file takes 1.05 s wall. One header takes 1.02 s. The 32-header file took 2.09 s before.

The hashes are still right. The sha256 in each result matches a separate createHash over the same bytes. I checked four files: 60 MiB and 500 MiB, owner not GNU and all-zero.

Each payload still costs budget. Two different 30 MiB descriptors are 60 MiB in total, under the 64 MiB default. They parse as complete in 29 ms with two different hashes. Two different 40 MiB descriptors are rejected in 20 ms. The error is the 67108864-byte budget error. The GNU type-4 version is rejected in 41 ms. Three different 30 MiB descriptors are rejected the same way. Three 1 MiB descriptors with different bytes give three hashes. A real file still works. /usr/bin/ls parses as complete with 7 tables and 8 entries.

New threads on 9b9d446

Greptile's P1 thread (4332429140) is now resolved. Greptile opened two new P2 threads on 9b9d446. Both are still unresolved, and both reproduce on 9b9d446. Neither comes from the fix. The lines they point at are not in the a67c319 diff (code read).

  • Budget errors give wrong advice. This is thread 4341235686, on ElfNotesProvider.ts line 128. I reproduced this on 9b9d446. I built a file with 32 headers sharing a 4 MiB name. It is 4,196,172 bytes. Through the CLI it exits 1 with code resource_constraint. The remediation says to review the worker memory limits and the available host memory. More memory cannot raise the cap, because the cap is the file's own length. The new commit 5d84922 ("name the note text budget instead of host memory") targets this thread. I read its message only and have not tested it.
  • Truncated notes blame the provider. This is thread 4341235704, on ElfNoteParser.ts line 168. I reproduced this on 9b9d446. I built a PT_NOTE that declares 20 bytes while the file holds 17. Those 17 are a 12-byte header, a 4-byte name and a 1-byte descriptor. parseElfNotes returns complete with 1 entry. Through the CLI it exits 1 with code unreadable_output instead of an invalid-input error. I did not run rea doctor, which that message suggests. The new commit a1ead5e ("reject note tables that extend past the file") targets this thread. It adds reader.require(offset, size) at the top of parseNoteStream, as the thread suggested. I read the diff only and have not tested it.

One observation, not a bug. The text, hashed and scanned counters are each checked against the file length on their own. So the total work on one parse can reach about three times the file length. I measured the pieces, not that worst case.

Not run

  • The 43974ac build: the "before" figures come from my last retest.
  • Greptile's two new P2 suggestions (not applied).
  • The all-zero GNU type-4 case at the ceiling before the fix.
  • The fix inside a running MCP server (whether other requests wait while a parse runs).
  • The CLI on Node 22 and 26 (Node 24 only).
  • ELF32 and big-endian forms of any case.
  • Full test suites, lint, format, knip, the docs build and the CI jobs. Only the PR's 8 test files and typecheck ran.

Thanks, mvanhorn, for the quick fix. It holds up against distinct payloads too, not only repeated ones.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.11
  • 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 / base: 9b9d446 / d8a9673 (GitHub's base for the PR). The fix commit is a67c319.
  • Other: GNU binutils objcopy (Fedora 44 package) to strip notes from a copy of ls. The box was shared: load average about 3 to 4 on 24 threads during the runs. The build ran on Node 24 only. The Node 22 and 26 runs reused that build.
Commands
# tree, from a read-only mirror of this repo
git -C ~/code/rea-mirror/rea.git archive 9b9d446544bc4d9c2f4ab85c391aa06e5a54d5ef | tar -x -C /tmp/rea-work/4837-r/head
# Node 24
npm --prefix /tmp/rea-work/4837-r/head ci --ignore-scripts
npm --prefix /tmp/rea-work/4837-r/head run build:cached
npm --prefix /tmp/rea-work/4837-r/head run test:prepare

# once per Node (22, 24, 26)
npm --prefix /tmp/rea-work/4837-r/head run test:focused -- \
  src/application/binaryDiagnostics/ElfNotesService.test.ts src/contracts/toolEffects.test.ts \
  src/domain/native/elfNotes.test.ts src/native/elf/ElfNoteParser.test.ts \
  tests/acceptance/elfNotesCli.test.ts tests/acceptance/tools/localToolContracts.test.ts \
  tests/boundary/filesystem/elfNotes.test.ts tests/boundary/mcp/elfNotesMcp.test.ts
npm --prefix /tmp/rea-work/4837-r/head run typecheck

# host-ELF test: strip the notes from a copy of ls, point a copy of the test file at it
objcopy --remove-section='.note*' /usr/bin/ls /tmp/rea-work/4837-r/probes/ls-nonotes

# probes: each builder writes a Buffer that goes to parseElfNotes from the built dist
node run4837.mjs /tmp/rea-work/4837-r/head/dist pay X 60 32       # P1, owner not GNU
node run4837.mjs /tmp/rea-work/4837-r/head/dist pay GNU4 60 32    # P1, all-zero GNU type 4
P_MAXFILE=536870912 P_MAXENT=256 node run4837.mjs /tmp/rea-work/4837-r/head/dist pay X 500 256
node run4837.mjs /tmp/rea-work/4837-r/head/dist distinct X 40 2   # two different 40 MiB descriptors
node run4837.mjs /tmp/rea-work/4837-r/head/dist trunctab          # PT_NOTE declares 20 bytes, file holds 17

# CLI
node scripts/rea.mjs inspect-elf-notes pay32.elf --json
Crafted ELF builders for the new probes (Node, little-endian ELF64)
// count PT_NOTE headers share one note whose descriptor is mib MiB.
// owner "X": not GNU. "GNU4": owner GNU, type 4, all-zero descriptor.
const pay = (owner, mib, count) => {
  const desc = Buffer.alloc(mib * 1048576, owner === "GNU4" ? 0 : 0x41);
  const nn = note(owner === "GNU4" ? "GNU" : "X", owner === "GNU4" ? 4 : 1, desc);
  const off = 64 + 56 * count;
  return Buffer.concat([
    ehdr64({ phoff: 64, phnum: count }),
    ...Array.from({ length: count }, () => phdr64({ type: 4, offset: off, filesz: nn.length })),
    nn,
  ]);
};

// count PT_NOTE headers, each pointing at its own note with a different mib-sized descriptor
const distinct = (mib, count) => {
  const notes = Array.from({ length: count }, (_, i) =>
    note("X", 1, Buffer.alloc(mib * 1048576, 0x41 + i)));
  let off = 64 + 56 * count;
  const hdrs = notes.map((n) => { const h = phdr64({ type: 4, offset: off, filesz: n.length }); off += n.length; return h; });
  return Buffer.concat([ehdr64({ phoff: 64, phnum: count }), ...hdrs, ...notes]);
};

// PT_NOTE declares 20 bytes; the file holds 17 (12-byte header, 4-byte name, 1-byte descriptor)
const trunctab = () => {
  const h = Buffer.alloc(12); h.writeUInt32LE(4, 0); h.writeUInt32LE(1, 4); h.writeUInt32LE(1, 8);
  return Buffer.concat([ehdr64({ phoff: 64, phnum: 1 }), phdr64({ type: 4, offset: 120, filesz: 20 }),
    h, Buffer.from("XYZ\0", "latin1"), Buffer.from([1])]);
};

ehdr64, phdr64 and note are the helpers from my earlier reviews. Each buffer goes to parseElfNotes(bytes, { path, sha256, bytes: bytes.length }, input) from the built dist/native/elf/ElfNoteParser.js, with input from inspectElfNotesInputSchema.parse({ path }).

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

cursoragent and others added 2 commits October 21, 2026 23:30
A PT_NOTE can declare a table whose alignment padding is past EOF while
every byte the parser reads still fits, and next equals the declared
size so the trailing range check never runs. The service then treated
that in-file table location as malformed provider output.

Require the declared table before reading notes. A short file is invalid
input, and the same note parses once the declared bytes are present.

Co-authored-by: morluto <[email protected]>
Text, hash, and scan refusals use a memory boundary whose ceiling is the
admitted image length. The shared memory recovery told callers to add
worker or host memory, which cannot raise that ceiling.

Those refusals now use the fixed-allowance recovery. Caller-selected
file-size and entry budgets still name the bound the caller can raise.

Co-authored-by: morluto <[email protected]>
@cursor

cursor Bot commented Oct 21, 2026

Copy link
Copy Markdown

Fixed the two open findings on 5d84922.

Declared note tables that extend past the file are invalid input. The parser requires the whole table before reading entries, so unread alignment padding past EOF is not reported as malformed provider output.

Text, hash, and scan budget refusals now use the fixed-allowance recovery. That ceiling is the admitted image length, so the reply no longer says to add worker or host memory.

npm run typecheck and the focused ELF note tests passed (23).

@CassieFox23

CassieFox23 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: Both of Greptile's P2 threads are fixed on 5d84922. A note table that runs past the end of the file is now refused as bad input. The budget error no longer tells callers to add memory. The earlier P1 fix still holds, and the PR's 47 tests pass on Node 22, 24 and 26.

Results

On head 5d84922, base d8a9673. This retest covers the two new commits since 9b9d446. They are a1ead5e and 5d84922. The "before" figures are from my retest of 9b9d446, same box and same probe files. I did not rebuild 9b9d446 this time. The probes call parseElfNotes on crafted ELF64 files, and the CLI runs use an empty HOME.

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
The PR's 9 test files (was 8 files and 43 tests on 9b9d446; new: ElfNotesProvider.test.ts with 3 tests, plus 1 parser test) 47 pass 47 pass 47 pass
npm run typecheck pass pass pass
Host-ELF test on a copy of ls with the notes removed (was 19 tests) 20 pass 20 pass 20 pass
Thread 4341235704: PT_NOTE declares 20 bytes, the file holds 17 (CLI) exit 1, invalid_request exit 1, invalid_request exit 1, invalid_request
Thread 4341235686: 4 MiB name x 32 PT_NOTE headers (CLI) exit 1, resource_constraint, fixed-allowance advice exit 1, resource_constraint, fixed-allowance advice exit 1, resource_constraint, fixed-allowance advice
P1: 60 MiB descriptor x 32 headers, owner not GNU (was 864 / 856 / 887 ms on 43974ac, 30.0 / 31.3 / 29.8 ms on 9b9d446) complete, 29.6 ms complete, 30.1 ms complete, 27.4 ms
P1: same, all-zero GNU type-4 descriptor (was 1,961 / 1,811 / 1,797 ms on 43974ac, 65.5 / 57.0 / 58.5 ms on 9b9d446) complete, 63.5 ms complete, 56.0 ms complete, 56.9 ms
My e3adf57 P1: 60,000 empty SHT_NOTE sections, one 60 MiB name rejected, 2.8 ms rejected, 2.6 ms rejected, 2.3 ms
Earlier #3: 68-byte ELF64, header table cut off rejected rejected rejected
Earlier #4: 232-byte ELF64, real section count in section 0 rejected rejected rejected
Earlier #2: 131,072 NULs then x complete, 1.7 ms complete, 1.3 ms complete, 1.3 ms
Earlier #1: 60 MiB name x 32 PT_NOTE headers rejected, 2.5 ms rejected, 2.5 ms rejected, 2.2 ms

The error messages from the earlier cases did not change.

The two P2 threads, before and after

Truncated notes blame the provider. This is thread 4341235704. I built a PT_NOTE that declares 20 bytes while the file holds 17. Those 17 are a 12-byte header, a 4-byte name and a 1-byte descriptor. The 3 padding bytes are missing.

9b9d446 5d84922
parseElfNotes complete, 1 table, 1 entry throws "ELF range 120 + 20 leaves the artifact."
CLI exit 1, code unreadable_output, remediation says to run rea doctor exit 1, code invalid_request, category invalid_input, remediation says to read the input contract

It is fixed. The CLI result is the same on all three Nodes; the parseElfNotes probe ran on Node 24 only. A file that declares 24 bytes (7 short) is rejected the same way. The control file, with the 3 padding bytes present, still parses as complete with 1 entry, and the CLI exits 0. Real files still parse: /usr/bin/ls and /usr/bin/env are both complete with 7 tables and 8 entries.

Budget errors give wrong advice. This is thread 4341235686. The file has 32 headers sharing one 4 MiB name. It is 4,196,172 bytes.

9b9d446 5d84922
CLI exit 1, resource_constraint, "Review the reported worker memory limits and available host memory. Retry with sufficient memory or a smaller artifact; REA retains tighter inherited limits." exit 1, resource_constraint, "The ELF note text, hash, and scan budget tied to the admitted image length is a fixed allowance. Worker memory limits, inherited limits, and additional host memory do not raise it. Select another complete input within the allowance when that preserves the needed observation. Repeating the unchanged request fails the same way."

It is fixed, and the CLI shows the same advice on all three Nodes. The message and the code did not change. A limit the caller sets still gets its own advice. Run the same file with --max-file-bytes 1000000. It says to raise max_file_bytes or pick a smaller file. One leftover, not part of Greptile's thread: the CLI JSON still has details.resource set to "memory".

The P1 fix still holds

Time still does not grow with the header count. Node 24, one 60 MiB descriptor:

Headers sharing it 1 8 32
Owner not GNU, now (5d84922) 26.9 ms 29.4 ms 30.1 ms
All-zero GNU type 4, now 58.5 ms 57.9 ms 56.0 ms

At the schema ceilings, 256 headers share one 500 MiB descriptor. That file takes 220 ms, against 234 ms on 9b9d446 and 58,202 ms on 43974ac. The all-zero GNU type-4 version takes 453 ms. Peak memory is the same as before (1,566 MiB). Through the CLI, the 32-header file takes 0.97 s wall and the 1-header file 0.98 s. Those are single runs.

Each payload still costs budget. In 27 ms, two different 30 MiB payloads parse as complete. In 19 ms, two different 40 MiB payloads are refused. They hit the 64 MiB budget error. The GNU type-4 version is rejected in 38 ms. Three different 30 MiB descriptors are rejected the same way.

New bot threads

None. All 10 review threads are resolved. There is no Greptile review on a1ead5e or 5d84922 yet, and I checked at 8:36 PM EDT. The cursor[bot] comment is a summary of the two fixes, not a finding. Greptile may still review later; I did not wait for it.

Not run

  • The 9b9d446 build: the "before" figures come from my last retest.
  • The independent sha256 comparison on this head. Only the 60 MiB test file's digest was matched to last round's.
  • The entry-count budget through the CLI. My try hit the text budget first.
  • The fixes inside a running MCP server. The PR's MCP test file ran and passed.
  • ELF32 and big-endian forms of any case.
  • Full test suites, lint, format, knip, the docs build and the CI jobs. Only the PR's 9 test files and typecheck ran.

Thanks, mvanhorn, for the PR, and thanks, morluto, for replying on both threads.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.11
  • 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 / base: 5d84922 / d8a9673 (GitHub's base for the PR). The new commits are a1ead5e and 5d84922.
  • Other: GNU binutils objcopy (Fedora 44 package) to strip notes from a copy of ls. The box was shared with other sessions: load average about 1.1 on 24 threads at the end. The build ran on Node 24 only. The Node 22 and 26 runs reused that build.
Commands
# tree, from a read-only mirror of this repo
git -C ~/code/rea-mirror/rea.git archive 5d849220fbd3a69502c132e4972b251c8dbd356e | tar -x -C /tmp/rt-4837/head
# Node 24
npm --prefix /tmp/rt-4837/head ci
npm --prefix /tmp/rt-4837/head run prepare
npm --prefix /tmp/rt-4837/head run build:cached
npm --prefix /tmp/rt-4837/head run test:prepare

# once per Node (22, 24, 26)
npm --prefix /tmp/rt-4837/head run test:focused -- \
  src/application/binaryDiagnostics/ElfNotesService.test.ts src/contracts/toolEffects.test.ts \
  src/domain/native/elfNotes.test.ts src/native/elf/ElfNoteParser.test.ts \
  src/native/elf/ElfNotesProvider.test.ts tests/acceptance/elfNotesCli.test.ts \
  tests/acceptance/tools/localToolContracts.test.ts tests/boundary/filesystem/elfNotes.test.ts \
  tests/boundary/mcp/elfNotesMcp.test.ts
npm --prefix /tmp/rt-4837/head run typecheck

# host-ELF test: strip the notes from a copy of ls, point a copy of the test file at it
objcopy --remove-section='.note*' /usr/bin/ls /tmp/rt-4837/probes/ls-nonotes

# probes: each builder writes a Buffer that goes to parseElfNotes from the built dist
node probe4837r3.mjs /tmp/rt-4837/head/dist pay X 60 32        # P1, owner not GNU
node probe4837r3.mjs /tmp/rt-4837/head/dist pay GNU4 60 32     # P1, all-zero GNU type 4
P_MAXFILE=536870912 P_MAXENT=256 node probe4837r3.mjs /tmp/rt-4837/head/dist pay X 500 256
node probe4837r3.mjs /tmp/rt-4837/head/dist distinct X 40 2    # two different 40 MiB descriptors
node probe4837r3.mjs /tmp/rt-4837/head/dist trunctab           # PT_NOTE declares 20 bytes, file holds 17
node probe4837r3.mjs /tmp/rt-4837/head/dist trunctabctl        # same, with the 3 padding bytes present
node probe4837r3.mjs /tmp/rt-4837/head/dist write mem4.elf mem 4 32   # 4 MiB name x 32 headers

# CLI, empty HOME
node scripts/rea.mjs inspect-elf-notes trunctab.elf --json
node scripts/rea.mjs inspect-elf-notes mem4.elf --json
node scripts/rea.mjs inspect-elf-notes mem4.elf --max-file-bytes 1000000 --json

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

Fork CI merged this branch into main at a73eac1. After that base, main
fixed the two failures:

- Setup's cursor-null diagnostic returned cleanup_incomplete when the
  Ghidra Java probe could not read an unrelated process environment
  (EACCES). Main records that withheld process as unverified.
- The real-browser service-worker deadline outlasted its teardown guard.
  Main selects a 2 second command timeout for that case.

.github/workflows/ci.yml stays at the previous tip. This fork push cannot
update workflow files.

Co-authored-by: morluto <[email protected]>
@gensokyo-dev

Copy link
Copy Markdown
Collaborator

Following the maintainer request to help integrate this contribution. I am verifying a clean ordinary merge of head 5d84922 with current main 407a718 in an isolated follow-up worktree, preserving your history. The previous failed shard was setup JVM cleanup (EACCES reading /proc//environ); the browser failure was deadline termination. Neither concerns the ELF feature; current main includes a targeted browser setup-deadline change. Initial parser/domain/provider/service/effects checks pass (34 tests); compiled CLI/MCP/filesystem and setup control are running. Next: readelf-backed real-file verification, resource measurements and fresh technical CI. No claim that the earlier unrelated failures are fixed yet.

@gensokyo-dev

Copy link
Copy Markdown
Collaborator

Observed your new 64b9dbc main merge and will preserve it. The independently verified tree also includes main 407a718; none of the ten intervening main-only file differences changes the ELF feature. I will use GitHub ordinary update-branch with expected_head_sha=64b9dbc37823981ad70473bf8af0da65fb68f14f to incorporate the latest base without rewriting history, then verify the exact resulting tree and wait for its CI. The real readelf-backed CLI/MCP checks and an actual Codex session passed; detailed evidence/costs will follow.

Comment thread .github/workflows/ci.yml Resolved
@gensokyo-dev

Copy link
Copy Markdown
Collaborator

The resulting a77143e ordinary update includes the newly merged #5600 base. Exact tree comparison caught one real PR regression inherited from 64b9dbc: the Windows curated lane drops sessionPathInputs.test.ts, directAnalysisSnapshotReplay.test.ts and rawBinaryMcp.test.ts. This is unrelated to ELF parsing but is an introduced coverage regression, so I am restoring those three main entries and running the existing curatedWindowsLane guard before/after. No test or gate will be weakened. Contributor history is retained; any push will be ordinary fast-forward only.

@gensokyo-dev

Copy link
Copy Markdown
Collaborator

Thanks: morluto has already supplied d4fbca9 restoring exactly those three Windows paths. I fast-forwarded the verification branch to that contributor/maintainer head instead of creating a duplicate fix. The existing guard reproduced 1 failure / 9 passes on a77143e, specifically the missing Windows-only path/snapshot coverage. Re-running the affected checks on exact d4fbca9 now; the prior local-selector refusal was not a test run and is not counted as passing evidence.

@gensokyo-dev

Copy link
Copy Markdown
Collaborator

Exact d4fbca9 retest: 37 compiled CLI/MCP/filesystem/setup/Windows-workflow checks passed, including all 10 curatedWindowsLane controls after the reproduced 1-failure before state. Main has since merged byte entropy #2331 (7aa1b51), which conflicts with the shared diagnostics registrations. I am taking this ELF restack onto that main, preserving both tools, then rerunning shared contracts/public workflows. CI for the previous head remains pending/queued, not counted as passed.

Merge main 7aa1b51 without dropping ELF notes or the newly integrated byte entropy tool. Keep separate provider identities and named contracts, CLI handlers, composition and catalog ownership. Retain the restored Windows curated suite and both contributor histories. Verification is recorded in PR morluto#4837 and tracking issue morluto#6262.
@gensokyo-dev

Copy link
Copy Markdown
Collaborator

Restack pushed normally as 36f19ae; no force-push. Both diagnostics tools now retain independent named contracts, provider identities, CLI handlers and catalog ownership; the pwntools catalog remains an explicit allowlist. Main entropy tests and ELF source checks pass together (48), all focused ELF/CLI/MCP/Windows-workflow checks pass (23), and shared diagnostics/summary/Evidence/product-catalog checks pass (16). Full static/docs and exact-head real-file/agent reruns are being finalized. @codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@gensokyo-dev

gensokyo-dev commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Maintainer follow-up verification — head 36f19aef2921d273f7d868f15b72909da173aa7b

Preserved the contributor's 64b9dbc37 update. An expected-head ordinary update incorporated main/#5600 (a77143e1b). Exact diff inspection found three unintentionally removed Windows curated test paths: the existing guard reproduced 1 failure / 9 passes. Adopted morluto's d4fbca9d4 restoration rather than creating a duplicate fix. The initial test:local invocation correctly refused that built-project path; the actual before/after evidence uses test:focused, not that refused command.

After main merged entropy #2331, resolved five shared registration/composition/catalog conflicts and normally pushed 36f19aef2 to this existing PR. Both tools retain separate named contracts, providers, CLI handlers and catalog bindings; pwntools keeps main's positive operation allowlist. No force-push, weakened gate, dropped contributor commit or Co-authored-by trailer in the maintainer follow-up. No new provider authority or target execution.

Executed on the final combined tree

  • 96 tests passed: 48 ELF/entropy domain, parser, provider, service and effect tests; 23 ELF CLI/MCP/filesystem, shared local-tool contracts and Windows-workflow guards; 16 shared diagnostics/summary/retained-Evidence/product-catalog checks; 9 README consistency checks.
  • npm run check:fast, complete npm run check, npm run docs:check, pre-push gate and diff checks passed. Architecture guards covered 1,791 source files. Pinned Node 24.18.0/npm 11.16.0 on Linux x64. The earlier exact d4fbca9d4 run also passed all 14 setup-diagnostics controls; this is separately scoped, not counted again among the final 96.
  • Public CLI/stdin-MCP: eleven pairs passed: /usr/bin/ls, /usr/bin/env, a GCC-built ELF, independently constructed no-notes ELF, malformed input, missing input, entry/file budgets, entropy preservation, and two additional compiler profiles. No inspected ELF was executed. readelf -W -n independently checked GNU build IDs and ABI versions; descriptor hashes/previews and owner bytes were checked directly against source ranges. CLI/MCP normalized results matched; advertised SDK-converted schemas validated under AJV 2020; the three initial real-file MCP Evidence records were read back exactly; source digests stayed unchanged. A 4,096-byte uniform-byte oracle returned exactly 8 bits/byte and four 1,024-byte blocks through both entropy adapters.
  • Additional real compiler profiles: GCC -m32 -nostdlib -Wl,--build-id=sha1 produced a little-endian ELF32 whose build ID appears in both program/section declarations. Clang -target powerpc64-unknown-linux-gnu -c produced a big-endian ELF64 object with a source-declared GNU build ID in its section. Both actual CLI/MCP results matched native readelf, source SHA-256 and descriptor-byte hashes, including format/byte order and the different declaration coverage. No target execution; these are Linux-host verification of compiler-produced artifacts, not native PowerPC/Windows runtime qualification.
  • Two actual Codex CLI 0.161.0 / gpt-6.1-sol sessions (initial integration and exact final tree), one actual inspect_elf_notes call each, no unauthorized calls. Both reported build ID, ABI, both declaration kinds, source digest and Evidence ID matching their actual replies, retaining runtime/catalog uncertainty. The exact-head runner initially exited 1 solely because its grader required program while the prompt permitted the equally correct program (PT_NOTE). The shared grader now accepts only explicit canonical/parenthesized semantic spellings and derives expected kinds from the actual build-ID entries. Both existing traces revalidated; no model rerun was used to erase the failed grader record.

Measured costs and limits

Completed task Wall Local process-family CPU Sampled peak family RSS
Final nine-pair public workflow, including native oracle/schema/Evidence checks 29.94s 43.76s 1181.22MiB
Final Codex session plus the initially over-strict grader 27.47s 8.81s 1066.19MiB
Additional compiler-produced ELF32/big-endian ELF64 public pairs 17.75s 23.84s 1138.84MiB

The initial measured public workflow (before the entropy-preservation pair was added) cost 24.98s / 37.06s / 1160.55MiB; its Codex session cost 27.32s / 7.98s / 1086.53MiB. The two actual agent sessions together used 171,714 input tokens, including 127,360 cached, and 697 output tokens. Whole-session counts include prompt/catalog/context/tool/final-answer costs, not just the ~5KiB ELF replies. Serialized bytes are not token measurements.

Public and agent runs were serial with explicitly forwarded 1GiB Node old-space settings; builds/checks used 2GiB and two compiler workers. These settings are not aggregate memory limits. RSS is a 500ms PID/start-identity process-family estimate; no sampled identity survived completion. OS/model caches and shared-host load were uncontrolled. Fresh CLI/server startup and later same-session MCP calls are included; the first unmeasured public trial, tests/builds/full CI and cloud inference CPU are not in these measurements. The public workloads differ, so no speedup or cold-cache comparison is claimed. Existing per-parse descriptor-range hash/GNU-scan reuse was inspected and preserved; no speculative global cache was added. Real Windows and exhaustive ELF dialect/maximum-input qualification were not performed.

Greptile's updated summary names exact head 36f19aef2, reports 5/5 confidence and no unresolved threads. The requested GitHub Codex code review could not run because its review quota is exhausted; it is not a passed review, and the two actual CLI sessions above are task verification, not a substitute claim of code review. CI for this exact head completed successfully: source/static/build/docs, all eight portable shards, Windows native-control build, four SQLite Node profiles, browser, agentenv, JavaScript recovery, EVM, network captures, binary layout, both recorded-crash distributions, website and native package baseline. Readiness passed using the contributor's existing declarations; this follow-up does not invent a new human review.

Merged and checked again

Merged normally, without admin/bypass, by gensokyo-dev at 2026-10-22 07:02:24 UTC as 2edf3b23c1465b7e6609b020d0eabfef438081a7. GitHub commit metadata retains mvanhorn as the primary author. No Co-authored-by trailer. All 54 PR files match reviewed head byte-for-byte; the 11 later main-only paths had no intersection with this change.

Switched the clean verification worktree to the actual merge commit, reused unchanged locked dependencies, rebuilt (12.02s), and all eleven public CLI/MCP pairs passed again, including entropy preservation and both compiler-produced bitness/endianness profiles. Post-merge nine-pair batch: 26.28s wall / 39.46s local CPU / 1191.74MiB sampled peak family RSS. Additional two compiler-profile pairs: 14.92s / 20.97s / 1172.36MiB. Both exited 0 with no surviving sampled identities. These are additional whole-workflow measurements under the same uncontrolled-cache/500ms-sampling limitations, not a speedup claim. Queue coordination: #6262.

@gensokyo-dev
gensokyo-dev merged commit 2edf3b2 into morluto:main Oct 22, 2026
44 checks passed
@morluto morluto mentioned this pull request Oct 25, 2026
3 tasks done
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request labels Nov 23, 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 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants