Skip to content

fix(elf): validate decoded section-name alignment - #9330

Closed
wunianze666-netizen wants to merge 2 commits into
morluto:mainfrom
wunianze666-netizen:codex/validate-elf-compression-alignment
Closed

wunianze666-netizen wants to merge 2 commits into
morluto:mainfrom
wunianze666-netizen:codex/validate-elf-compression-alignment

Conversation

@wunianze666-netizen

@wunianze666-netizen wunianze666-netizen commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Reject malformed decoded section-name alignment before interpreting ELF names. A compressed table declaring ch_addralign = 3 currently yields complete CLI/MCP Evidence with decoded names; the same inputs now return the existing input-format error. No separate issue is linked because this was independently reproduced.

Problem and expected behavior

On frozen main b81da90354e3ce4c1e01c5e5a06f4794f15f436a, changing only the compression header's decoded alignment to 3 (or the highest class bit plus 1) still returns .note.gnu.build-id and complete note coverage. The actual CLI exits 0, and the actual stdio SDK returns successful Evidence for all four malformed class/byte-order cases.

The ELF gABI compression-header contract defines ch_addralign by sh_addralign: zero or a positive power of two. Reject other alignments before decompression/name interpretation. Preserve zero, one, and large legal powers of two without converting ELF64 alignment to a lossy JavaScript Number.

Change and scope

Validate the decoded alignment once in decodeElfSectionNameTable, the existing owner used by both the note parser and native section-directory reader. Reuse its malformed outcome; the callers retain their existing error projection. There is no new decoder, parallel admission path, setting or capability. Ordinary passive format correction within existing scope; a separate maintainer scope decision is not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the shared compressed section-name table decoder, before allocation/decompression. Both consuming parsers are checked by the regression; no consumer-side repair is added.
  • Contribution scope fit and linked maintainer decision: existing offline ELF inspection; not applicable.
  • CLI and MCP/tool-catalog contract: unchanged fields and advertisement; malformed alignments now use invalid_request / invalid_input.
  • Provider, bridge, target-format, or platform compatibility: ELF32/64, both byte orders, zlib/Zstandard synthetic inputs on Windows/Node. No target or external engine execution.
  • Evidence, artifact, provenance, or reconstruction contract: valid complete normalized results, selected paths and artifact SHA-256 are preserved; malformed headers no longer produce completed Evidence.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): existing file selection, read-only access, budgets, decoder-window policy and cleanup remain.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): none; the owning ELF guide documents the admission rule.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: four class/endianness regressions exercise both shared consumers, each covering both codecs, zero/one/highest-bit valid controls and 3/highest-bit-plus-one invalid controls.
  • Base reproduction or other evidence: with the frozen production owner unchanged, exactly 4 new failures / 60 passes / 1 existing host-ELF skip; after the fix, 64 passes / the same skip. The skip is the existing host ELF test on Windows, not a skipped new regression.
  • User-visible CLI/MCP output (if applicable): per phase, four actual compiled CLI calls and eight actual SDK calls. Baseline accepts all malformed samples. Candidate rejects the two CLI and four SDK malformed samples with canonical input errors; all legal normalized results are equal to baseline. Input bytes and artifact identities are checked.
  • Remaining proof gaps: authored format fixtures, not real target-architecture execution, real core capture, Ghidra, browser, or a complete Windows package. Full local check is not claimed green; see below.

For boundary fixes, identify the applicable boundary regressions
and lifecycle regressions
covered by the evidence above, and explain relevant gaps.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

Current head 7ea6912bfb7acccb9024763fbd2dadcefcc6ec51 normally merges accepted main 2ac85788271f8650da0b46d680a41c06e197cde2 (#9332). That accepted one-line Knip entry registration repairs #9295. The original fix and all existing authors/commits remain; the PR diff still contains its original three files. No unmerged repair was copied.

  • Configuration-only update: no runtime test rerun is claimed.
  • Current npm run build:cached: 3 successful / 3 cached. Matching runtime artifacts were restored; no fresh compilation is claimed.
  • Current npm run knip: passed with the accepted entry present. This closes the recorded unused-verifier blocker; it is not a claim that the complete optional check chain passed.
  • Relative to the previous head this merge changes only knip.json. Runtime source, tests and dependency inputs are byte-identical, so the runtime suite and CLI/SDK matrix were not repeated. Earlier runtime results remain explicitly labeled below; no fresh runtime or platform qualification is claimed for this configuration-only update.
  • Normal merge/push and pre-push checks completed; remote head equals the current head above. New-head CI is checked after push; no earlier-head run is counted.

The complete npm run check architecture/production-Knip/typed-lint chain was not rerun. Broader platform/provider gaps below remain; no old CI checkout, unread shard or sibling platform result is borrowed.

Previous revision validation at f260409
  • Exact parser/provider/public CLI files: node scripts/run-exact-tests.mjs run src/native/elf/ElfNoteParser.test.ts src/native/elf/ElfNotesProvider.test.ts tests/acceptance/elfNotesCli.test.ts — 78 passed / 1 existing Windows host-ELF skip, no name filtering.
  • npm run build:cached — frozen baseline and candidate each 3 successful / 1 cached, both with actual compilation.
  • Actual compiled inspect-elf-notes <path> --json — baseline/candidate four-case matrices; complete legal results unchanged and malformed cases corrected to exit 1/input errors.
  • Actual production stdio SDK, native family/full profiles — complete inspect_elf_notes ToolDefinition retrieved by name once per connection and used for all eight cases. Both declared schemas pass Ajv2020 meta-schema checks; actual input/success values validate through Ajv and SDK. Error projections validate against the canonical error schema. Selected artifact path/digest and file bytes are checked.
  • Actual CLI args/options/globals validation and schema comparison — passed; CLI and named MCP schema JSON are equal before/after.
  • npm run check:ci:fast, npm run docs:check, npm run verify:test-discovery, git diff --check — passed. Discovery verifies registration, not execution of the entire test corpus; repository lint warnings remain.
  • Full npm run check was not repeated on this revision. The known main Knip failure is #9295, unused scripts/verify-real-ghidra-function-bundle.mjs; repair #9300 remains open/unmerged. Fresh main Knip blob 4d24b67dd53c1ec34568e26015b71974613554b2 is unchanged and still lacks the entry. No unmerged repair was copied or gate disabled. Later full-check stages are unverified here.

Windows, Node 24.22.1. New-head CI is pending after publication. No performance or process-memory claim.

Compatibility, safety, and release

  • Breaking changes or migration steps: valid tables keep their behavior; malformed declared alignments require a corrected input file. Unknown compression still follows its existing unsupported-name policy.
  • Real Hopper/Ghidra, browser, or OS coverage: local Windows Node parser/CLI/stdio SDK only; no live provider or architecture-host qualification.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: passive file-format admission, without target execution/mutation, permission changes or altered resource limits.

Author readiness

Human owner: @wunianze666-netizen

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

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T04:22:20.751809Z f260409 PR opened
ℹ️ 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.

@greptile-apps

greptile-apps Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge; no actionable code defect was found.

Summary

The PR checks decoded section-name alignment in the shared ELF decoder before decompression.

  • Compressed ELF section names reject invalid alignment values.

Reviews (4) · Last reviewed commit: "Merge commit '2ac85788271f8650da0b46d680..." · Reviewed by Greptile

@morluto

morluto commented Nov 19, 2026

Copy link
Copy Markdown
Owner

The current-base replacement is #12193. It validates decoded alignment in the shared ELF compression header reader before inflation, with ELF32 and ELF64 controls. The combined head is validated and queued for squash merge. Thanks for the original fix.

@morluto morluto closed this Nov 19, 2026
morluto added a commit that referenced this pull request Nov 19, 2026
* fix(elf): reject invalid section table and zlib declarations

Refs #10149, #10148, #9330.

Co-authored-by: Nianze Wu <[email protected]>

* fix(elf): share section count admission with carrier readers (#12196)

fix(elf): admit section tables before carrier recognition

---------

Co-authored-by: Nianze Wu <[email protected]>
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working labels Nov 22, 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 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants