Repository navigation
feat(elf): inspect PT_NOTE and SHT_NOTE tables - #4837
Conversation
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.
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; no new blocking issue was found. SummaryAdds
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"]
Reviews (8) · Last reviewed commit: "chore(elf): preserve both diagnostics wo..." · Reviewed by Greptile |
There was a problem hiding this comment.
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 countCrafted 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
|
Addressed all five in da5d634:
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. |
There was a problem hiding this comment.
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-nonotesCrafted 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.
|
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. |
|
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 Edit (21 Oct): Greptile's P1 is fixed on 9b9d446. See the retest. ResultsOn head 43974ac, base 9258df0. The new P1 rows were measured in process, with
At e3adf57 the 60,000-section file came back New findingP1,
The time grows in step with the header count. Hashing a 60 MiB buffer 32 times with plain At the schema ceilings ( That this blocks other MCP requests comes from my reading of Not run
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
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 --jsonCrafted 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,
]);
};
🤖 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.
|
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. |
|
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. ResultsOn 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
The messages did not change. They read The P1 fix, in numbersTime no longer grows with the header count. Node 24, one 60 MiB descriptor:
At the schema ceilings, 256 headers share one 500 MiB descriptor. The ceilings are The hashes are still right. The sha256 in each result matches a separate Each payload still costs budget. Two different 30 MiB descriptors are 60 MiB in total, under the 64 MiB default. They parse as New threads on 9b9d446Greptile'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).
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
Thanks, mvanhorn, for the quick fix. It holds up against distinct payloads too, not only repeated ones. Test setup
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 --jsonCrafted 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])]);
};
🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊 |
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]>
|
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.
|
|
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. ResultsOn 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
The error messages from the earlier cases did not change. The two P2 threads, before and afterTruncated 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.
It is fixed. The CLI result is the same on all three Nodes; the 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.
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 The P1 fix still holdsTime still does not grow with the header count. Node 24, one 60 MiB descriptor:
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 New bot threadsNone. 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
Thanks, mvanhorn, for the PR, and thanks, morluto, for replying on both threads. Test setup
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]>
|
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. |
|
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. |
|
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. |
|
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. |
|
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.
|
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 |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Maintainer follow-up verification — head
|
| 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.
Summary
Add
inspect_elf_notes/inspect-elf-notesfor one explicit local ELF32/ELF64image. The workflow reads
PT_NOTEprogram headers andSHT_NOTEsectionsindependently 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.propertyentries in ordinary GNU/Linux binaries parse.Usage
MCP:
inspect_elf_noteswith an absolutepath.Tests
npm run check:fastnpm 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)/bin/ls,/usr/bin/env, and a gcc-Wl,--build-idbinary: GNU property, build-id, and ABI-tag notes listed in both tablesDemo
Author readiness
Human owner: @mvanhorn