Repository navigation
fix(node-sea): bound ELF note scans by the notes a carrier holds - #8031
Conversation
Artifact classification probes every ELF root for a Node SEA note. Each PT_NOTE program header was scanned on its own, one read per note, so headers that declare the same note bytes multiplied the work: a 295 KB ELF with 4,096 such headers kept inspect-artifact busy for about three and a half minutes. Every note header takes at least 12 bytes, so disjoint tables hold at most one note per 12 file bytes. The scan now stops there. Past that count the remaining tables are unreadable: an ELF without a confirmed blob keeps its native classification, and a confirmed blob fails closed.
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 actionable issues were found. SummaryBounds ELF note-header reads with one shared budget of
Acknowledged behavior:
Supersession could not be checked on GitHub because authentication was unavailable. Local history contains no later change. Reviews (1) · Last reviewed commit: "fix(node-sea): bound ELF note scans by t..." · Reviewed by Greptile |
Summary
Artifact classification runs the embedded Node SEA probe on every ELF root (
inspect_artifact/inspect-artifact, throughembeddedProbes.nodeSea()).locateElfNotesinsrc/artifacts/nodeSea/NodeSeaLocation.tsscans eachPT_NOTEprogram header (up to 4,096) on its own, with one awaited 12-byte read per note header. Program headers that declare the same note bytes therefore rescan those bytes once per header, so the work grows as headers × notes rather than with the file size.A 294,976-byte ELF64 with 4,096
PT_NOTEheaders over the same 64 KiB of zero bytes (5,461 empty notes) makeslocateNodeSeatake 208 s on main. With this change it takes 277 ms.Node finds the blob by walking
PT_NOTEsegments and returning the firstNODE_SEA_BLOBnote (deps/postject/postject-api.h#L127-L167 at v24.10.0). An ELF note entry is a 12-byte header followed by its padded name and descriptor, and the scanner already rejects entries shorter than 12 bytes. So tables that do not overlap can hold at mostfileSize / 12notes in total.No issue is linked. I searched open and closed PRs and issues for "node sea note", "PT_NOTE", "locateNodeSea", "NodeSeaLocation", "node sea quadratic" and "note table". Only #7000 (the original reader) and unrelated ELF note PRs came up. The one open PR touching Node SEA files, #7177, edits
docs/node-sea.mdelsewhere; it already conflicts with main in other files, and this branch adds no conflict with it.Problem and expected behavior
PT_NOTEheaders over 5,461 empty notes (295 KB)undefinedundefined(classified as a plain ELF)undefinedundefinedNODE_SEA_BLOBnote followed by 341 empty notes (7.8 KB){carrier:"elf", blobOffset:3676, blobLength:48}Expected: the note scan is bounded by the file size, not by headers × notes.
Change and scope
locateElfNotesnow gives every note table of a carrier one shared budget offloor(fileSize / 12)note headers. The same budget covers theSHT_NOTEfallback, which only runs when no program-header table is readable, so the two never scan the same file.NODE_SEA_ELF_NOTES_REPEATEDmessage. This matches the existing rule that a blob found beside an unreadable note table fails closed (NODE_SEA_ELF_TABLE_TRUNCATED).docs/node-sea.mddescribes the bound.ELFs whose note tables do not overlap, which covers all normal files, cannot reach the budget and are unchanged. A carrier that repeats note tables far enough to exceed the budget is crafted. Node would still run it, but REA now reports a format failure for it instead of the blob.
Not included: a single very large
PT_NOTEtable full of empty notes is still read one 12-byte header at a time. That cost is linear in the table size, not headers × notes.Contribution scope: a robustness fix in an existing reader; a maintainer scope decision is not applicable.
Contract and boundary impact
locateElfNotes/scanElfNoteTableinsrc/artifacts/nodeSea/NodeSeaLocation.ts.docs/public/product-catalog.json), package, or installation impact: none;docs/node-sea.mdupdated.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
src/artifacts/NodeSeaArtifactReader.test.ts, "reads repeated PT_NOTE declarations at most once per note the file holds".repeatedNoteElfbuilder with 64PT_NOTEheaders.FileHandle.readcalls rather than wall-clock time, so the result is deterministic.NODE_SEA_ELF_NOTES_REPEATED.NodeSeaLocation.tsandNodeSeaBlob.tsreverted to main, the test fails withexpected 21890 to be less than or equal to 711(read calls).locateNodeSeaon the generated files on macOS arm64 with Node 24.22.1.npm run verify:node-sea) was not run. The CLI acceptance test, which builds a blob with the local Node, passes.locateNodeSeastill returnsundefinedfor 300 real Android NDK.sofiles.For evidence-bearing changes:
Validation performed
npx vitest run src/artifacts/NodeSeaArtifactReader.test.ts:NodeSeaArtifactReader.test.ts,nodeSea/NodeSeaBlob.test.tsandArtifactEmbeddedFormatProbes.test.ts: 65 passed;EmbeddedArtifactExtraction.test.ts,ArtifactGraphConstruction.test.ts,ElfNoteParser.test.ts,tests/boundary/filesystem/artifactComparisonNodeSea.test.tsandartifactProvider.extractionAdmission.test.ts: 139 passed, 1 skipped.npm run compile,tests/acceptance/nodeSeaCli.test.ts,tests/boundary/mcp/nodeSeaMcp.test.tsandtests/acceptance/artifactComparisonNodeSea.test.ts: 11 passed.npx tsc --noEmit: 0 errors.npx oxlinton the changed files: 0 errors. The complexity, max-depth and max-lines warnings are the same as on main.npx oxfmt --checkon the changed files: clean.npm run verify:module-boundaries: passed.node scripts/check-doc-facts.mjs: passed.Compatibility, safety, and release
Author readiness
Human owner: @Dragolone
Before merge
type(scope): outcome.