Skip to content

fix(errors)!: refuse corrupt managed, IL2CPP and universal Mach-O bytes as a malformed target - #14224

Merged
morluto merged 2 commits into
mainfrom
fix/malformed-target-format-mappers
Nov 24, 2026
Merged

morluto merged 2 commits into
mainfrom
fix/malformed-target-format-mappers

Conversation

@morluto

@morluto morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Follow-up to #14195, which left three formats with their own error mappers that still reported a selected file's corrupt bytes as an invalid_format path issue (invalid_request).

Root cause

managedInspectionInputFailure, Il2cppMetadataProvider.failureForPrimary and the Mach-O slice selection mappers (requireSelectedNativeImage, requireSelectedNativeImageFromReader) each built AnalysisInputError with reason: "invalid_format" on the field that selected the file. The arguments were valid; the bytes were the problem. The Mach-O container reader also flattened every failure to { kind: "malformed", message }, losing truncation and its own unsupported category, so a mapper could not project the real class without reading message text.

Structural fix

  • Mach-O owner (machoImageSelection.ts): the container failure is now { kind: "format", message, failure: ParseFailure }, raised once. truncated only where this reader measured the end (header needs-data, a slice prefix with no CPU identity); unsupported from the container reader's own range category (alignment exponent > 52); malformed otherwise, with the slice's offset. selectionError in machoSliceSelection.ts projects it as AnalysisMalformedTargetError / AnalysisUnsupportedTargetError at the universal file's path. Refused selections stay invalid_request on the architecture field. SliceSelectionInput.pathField is removed (nothing names a path field any more). Consumers updated: Il2cppBinaryImage, AppleDispatchMetadata, readBinaryContainer, the test fixture.
  • Managed owner (managedReaderFailure.ts): managedInspectionTargetFailure projects the reader's issue code: rule violations → malformed pe-cli target with field (the reader's scope) and offset; unsupported-metadata / unsupported-signature → unsupported target; resource-limit → left to its producer. The unused inputField parameter is removed.
  • IL2CPP owner (Il2cppBinaryFormat.ts): the binary reasons are split into malformed: ["malformed-container"] and linkConflict: [...]. The provider projects metadata and binary format failures through parseFailureAnalysisError at each file's own path, and a link conflict through linkConflict.

Decision tables

Managed PE/CLI (single input per call; comparison runs one inspection per side)

Case Input at fault Code Field / path Reason
PE/CLI rule broken (section past EOF, bad stream, row, heap index) the selected file unsupported_target, format_failure: malformed, format: pe-cli details.path = that file; details.field = reader scope The reader established a rule violation in those bytes.
Comparison side malformed that side same details.path = that side's file Each side is inspected alone; its own path names it, and the completed left side stays in argument_observations.
unsupported-metadata, unsupported-signature none (coverage) unsupported_target details.path A newer valid layout is not corrupt.
resource-limit none unchanged (producer's resource refusal) n/a A budget, not the bytes.

Universal Mach-O slice selection

Case Input at fault Code Field / path Reason
Overlapping slices, range past EOF, misaligned, zero slices universal file unsupported_target, malformed, format: macho details.path The container breaks its own rules.
Selected slice ends inside its Mach-O identity universal file unsupported_target, truncated details.path, details.offset = slice Measured end inside the structure.
Slice header disagrees with its FAT entry universal file unsupported_target, malformed details.path, details.offset = slice Two records in one file disagree; the format requires them to match, so it is not a cross-input conflict.
Alignment exponent above 52 none (coverage) unsupported_target details.path The container reader classifies it as unsupported.
Unknown slice, missing or ambiguous architecture, architecture on a thin file the caller's selection invalid_request, invalid_value architecture / binary_architecture The file is fine; the request names nothing in it.

IL2CPP (path + optional binary_path)

Case Input at fault Code Field / path Reason
Corrupt or truncated metadata (also when read on demand while linking) metadata unsupported_target, malformed/truncated, format: il2cpp-metadata details.path = metadata The metadata owner raised it.
unrecognized-magic, unsupported-version (not 24/27/29/31/39) none (coverage) unsupported_target details.path = metadata Unchanged; unsupported is not malformed.
malformed-container (binary or its universal container) binary unsupported_target, malformed/truncated, format: il2cpp-binary or macho details.path = binary The binary's own bytes.
Binary parses but does not link: *-not-found, ambiguous-*, invalid-method-pointer, invalid-method-token, invalid-type unresolved invalid_request, invalid_value on both path and binary_path (--binary in the CLI), no inspect_input_contract recovery both fields; partial observation keeps both SHA-256s and sizes Two well-formed records disagree. They may be from different builds, either may be damaged, or the registration layout may be outside coverage. This is the more conservative classification: it calls neither file corrupt, and the remediation says what to check.
Unknown slice in binary_path the caller's selection invalid_request binary_architecture As above.

Design notes

  1. Unsupported is not malformed. Each owner keeps its own unsupported class: IL2CPP versions outside 24/27/29/31/39 and unknown magic, managed unsupported-metadata/unsupported-signature, a Mach-O FAT alignment the container reader rejects as unsupported. Mach-O CPU types REA cannot decode in a selection remain the caller's selection (architecture_not_present), never malformed. IL2CPP link failures that might be an unknown registration layout are reported as a conflict, not as corrupt bytes.
  2. Composite inputs report per input. Every malformed refusal names the exact file in details.path: metadata versus binary_path, and the universal file (with the slice's offset) for slice faults. IL2CPP keeps both identities (path, SHA-256, bytes) in the partial observation. When both files parse but disagree, the refusal lists both fields and blames neither.
  3. Transient faults keep their class. Nothing new catches I/O, cancellation or changed-file errors. Those paths run before the new projections (AnalysisError passthrough, the signal.aborted check, ArtifactReaderFailure handling), and the existing cancellation and artifact_changed tests still pass. Malformed and unsupported refusals are not retryable and offer "choose another target". Selection errors keep "fix the request". The link conflict's remediation names the pair.
  4. One system of record. The class comes from the owner's typed fact: the managed issue code, the Mach-O ParseFailure kind and the container's category, and the IL2CPP reason category list. Nothing is derived from message text. Where an owner does not establish truncation (for example the FAT table "is truncated" malformed reason from machoContainer), the projection keeps the owner's malformed.
  5. Contract evolution. Breaking for callers that parse code, marked fix(errors)!: with a BREAKING CHANGE: footer listing the operations. No detail fields are renamed. The new fields are the additive format_failure, format, field and offset from fix(errors): refuse malformed target bytes as a target, not invalid input #14195's projection.

Tests

  • Owner level: managedReaderFailure.test.ts (new: malformed with field and offset, offset omitted when unknown, both unsupported codes, limit and foreign causes). MachoSliceSelection.test.ts: the owner failure shape (malformed, truncated slice, unsupported alignment), plus both public mappers (buffer and reader) for unknown slice → architecture, truncated slice, header/table disagreement and unsupported alignment. il2cppBinaryFile.test.ts: overlap, header disagreement and subtype mismatch as malformed binary targets; a new truncated slice case and an unknown-slice control. il2cppMetadataProvider.test.ts: truncated metadata, corrupt binary container, corrupt metadata found while linking, and the valid-but-inconsistent pair (both issues, invalid_request, no recovery, both identities).
  • Public workflows: stableArtifactParserFailureCli gains the single-input cases: 3 managed commands (section past EOF) and inspect-go-binary, inspect-rust-binary, inspect-dwarf-units, inspect-native-initializers (overlapping universal Mach-O). The managed per-command copy in managedCliOutput is removed. New il2cppMetadataCli CLI+MCP test: corrupt metadata names the metadata, a truncated universal slice names the binary, and an inconsistent pair lists both fields. universalSliceMcp, managedMemberComparisonCli (each side now gets its own malformed file, so the path names the side), il2cppStructuralExtentsCli and existing il2cppMetadataCli expectations are updated.
  • Kept: argument errors (directory, symlink, missing file, view JSON), architecture selection errors, cancellation, artifact_changed and identity coverage.
  • Mutation checks: making unsupported-signature fall through to malformed fails the managed owner test, and disabling the link-conflict branch fails two IL2CPP provider tests. Both pass again after revert.

Validation

  • npx vitest run on 67 affected source and boundary files (Mach-O, IL2CPP, managed, Go, Rust, DWARF, initializers, Apple dispatch, MCP universal slice): 2270 passed, 20 skipped. 43 managed source/boundary/composition files: 914 passed. tests/boundary/cli/dylibResolutionCli.test.ts needs the compiled CLI (dist/) and was not run locally.
  • In-process CLI probes from source (createCli() through serveInProcessCli) confirmed each new acceptance expectation: managed pe-cli malformed with field/offset, four native commands on an overlapping universal file (macho, file-snapshot-hash retained), an unknown slice staying invalid_request on architecture, and the three IL2CPP pair cases (including CLI field binary).
  • A scoped tsc over the changed sources and tests found no errors (only pre-existing frida typing errors outside this change). oxlint reported no errors, oxfmt ran on every changed file, and scripts/verify/architecture-guards.mjs passed.
  • Not run locally, so CI must confirm: the tests/acceptance/* suites and managedMemberComparisonCli (they need dist/), the full typecheck, and docs:check.
  • docs/user-visible-errors.csv is unchanged: no error tag or classification changed.

Docs

docs/il2cpp-metadata.md (failure categories malformed/conflict/unsupported, damaged-metadata projection, FAT table wording), docs/guides/managed/managed-code-analysis.md, docs/guides/native/go-binaries.md (damaged universal file).

Real-provider verification scope

None needed. All three are local static parsers.

Remaining cleanup

  • managedMetadataFailureStatus still reports unsupported-signature as malformed in inventory status. The refusal path now calls it unsupported. Aligning the inventory status changes result payloads, so it is left for a separate change.
  • invalid-method-token covers both a metadata-internal duplicate MethodDef row and a cross-file token range. Splitting it at the producer would let the duplicate case blame the metadata. It is reported as a conflict for now, the conservative choice.
  • machoContainer reports "FAT header/table is truncated" as malformed; it could carry a typed truncation fact. Not changed here because that reader is shared with the artifact reader producers being reworked on another branch.

…es as a malformed target

Three formats had their own error mappers that still reported a selected
file's corrupt bytes as an invalid_format path issue (invalid_request):
managedInspectionInputFailure, Il2cppMetadataProvider and the Mach-O slice
selection mappers. Each now projects its format owner's own failure through
AnalysisMalformedTargetError at the path of the file whose bytes are at fault.

- Managed PE/CLI: a broken rule is a malformed pe-cli target with the
  reader's scope and offset; unsupported-metadata and unsupported-signature
  are unsupported targets; resource limits stay with their producer.
- Universal Mach-O: the container reader raises a ParseFailure once
  (malformed, truncated where it measured the end, unsupported from the
  container's own category), and requireSelectedNativeImage(FromReader)
  project it at the universal file's path. An unknown or ambiguous
  architecture stays invalid_request on the architecture field.
  SliceSelectionInput.pathField is removed.
- IL2CPP: metadata and binary format failures each name their own file. A
  binary that parses but does not link to the metadata is a link conflict:
  invalid_request with invalid_value issues on both path and binary_path,
  no input-contract recovery, and the partial observation keeps both file
  identities. Neither file is called malformed.

BREAKING CHANGE: inspect_managed_artifact, inspect_managed_members,
inspect_managed_native_boundaries, compare_managed_members,
inspect_il2cpp_metadata, inspect_go_binary, inspect_rust_binary,
inspect_dwarf_units and inspect_native_initializers report corrupt or
truncated target bytes as code unsupported_target with details.path,
format, format_failure and reason instead of invalid_request with an
invalid_format issue. IL2CPP link conflicts list both path and binary_path
with reason invalid_value instead of one invalid_format binary_path issue.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T01:09:35.423078Z
We couldn’t complete this review. Comment @codex review to try again.
778ff03 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

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

Summary

This PR reports corrupt managed, IL2CPP, and universal Mach-O bytes as target failures rather than bad path arguments.

  • Managed inspections name the file whose PE/CLI bytes break a format rule.
  • Universal Mach-O errors point to the file and retain the failure type.
  • IL2CPP refusals distinguish damaged files from files that do not match.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Reader[Format reader] --> Failure{Typed failure}
  Failure -->|Malformed or truncated| Target[Target refusal at the affected file path]
  Failure -->|Unsupported form| Unsupported[Unsupported target]
  Failure -->|Architecture selection| Request[Request error on architecture]
  Failure -->|IL2CPP link conflict| Pair[Request error naming both files]
Loading

Reviews (2) · Last reviewed commit: "Merge main into fix/malformed-target-for..." · Reviewed by Greptile

@morluto
morluto enabled auto-merge (squash) November 24, 2026 01:16
@morluto
morluto disabled auto-merge November 24, 2026 01:20
# Conflicts:
#	tests/acceptance/stableArtifactParserFailureCli.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant