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

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.
This commit is contained in:
morluto authored and GitHub committed 2026-11-23 20:23:19 -05:00
1 parent 1a43f56354
commit 57f4e3c4bd
24 files changed
+934 -296

No files matched your search

+15 -2
View File
@@ -15,8 +15,15 @@ export const IL2CPP_BINARY_FAILURE_REASONS = {
"type-nesting-capacity",
"native-type-text-capacity",
],
malformed: [
"malformed-container",
/** The binary's own container bytes break their format's rules. */
malformed: ["malformed-container"],
/**
* The binary's container parsed, but its registration, pointers, tokens or
* types do not agree with the metadata. The pair may come from different
* builds, either file may be damaged, or the registration layout may be
* outside coverage, so no single file is established as at fault.
*/
linkConflict: [
"code-gen-modules-not-found",
"ambiguous-code-gen-module",
"code-registration-not-found",
@@ -50,6 +57,12 @@ const isUnsupported = (reason: Il2cppBinaryFormatReason) =>
reason,
);
/** Whether a link failure is a disagreement between the two files, not one file's bytes. */
export const isIl2cppLinkConflict = (reason: Il2cppBinaryFailureReason) =>
(IL2CPP_BINARY_FAILURE_REASONS.linkConflict as readonly string[]).includes(
reason,
);
/**
* A native image REA cannot link, either outside coverage or inconsistent
* with the metadata. The stable `reason` names the IL2CPP rule; a capacity
+6 -5
View File
@@ -39,9 +39,8 @@ import {
IL2CPP_BINARY_BYTES,
} from "./Il2cppBinaryFormat.js";
/** Selection failures name the binary's inputs and IL2CPP's public spellings. */
/** Selection failures name the binary's architecture input and IL2CPP's public spellings. */
const IL2CPP_SLICE_SELECTION_INPUT: SliceSelectionInput = {
pathField: "binary_path",
architectureField: "binary_architecture",
spelling: Object.fromEntries(
Object.entries(IL2CPP_SLICE_SELECTORS).map(([publicName, selector]) => [
@@ -53,8 +52,9 @@ const IL2CPP_SLICE_SELECTION_INPUT: SliceSelectionInput = {
/**
* Select the thin image of the caller's binary: IL2CPP's `binary_architecture`
* maps onto the shared slice selector here, once, and a selection failure
* names `binary_architecture` or `binary_path`.
* maps onto the shared slice selector here, once. A refused selection names
* `binary_architecture`; a universal container format failure is a target
* refusal at the binary's own path.
*/
export const requireIl2cppBinaryImage = (
operation: string,
@@ -187,7 +187,8 @@ export function* openImageSteps(
// container's architecture names no CPU family this reader decodes.
if (!selected.ok)
throw new Il2cppBinaryFormatFailure(
selected.error.kind === "malformed"
selected.error.kind === "format" &&
selected.error.failure.kind !== "unsupported"
? "malformed-container"
: "unsupported-container",
selected.error.message,
+49 -21
View File
@@ -3,9 +3,11 @@ import {
Il2cppBinaryFormatFailure,
IL2CPP_BINARY_BYTES,
IL2CPP_BINARY_FORMAT,
isIl2cppLinkConflict,
} from "./Il2cppBinaryFormat.js";
import {
isParseLimit,
parseFailureAnalysisError,
parseLimitConstraint,
} from "../domain/parseFailureAnalysisError.js";
import { Il2cppMetadataFormatFailure } from "./Il2cppMetadataFormat.js";
@@ -75,6 +77,39 @@ const inferredReferenceForm = (architecture: string) =>
architecture === "arm64"
? "an adjacent ADRP+ADD pair"
: "RIP-relative LEA/MOV";
/**
* Both files parsed, but the binary does not link to the metadata. They are
* two well-formed records that disagree, and nothing establishes which one
* is wrong, so neither is called malformed: the refusal lists both selecting
* fields, and the caller's partial observation keeps both files' identities.
*/
const linkConflict = (
binaryPath: string,
metadataPath: string,
cause: Il2cppBinaryFormatFailure,
): AnalysisInputError =>
new AnalysisInputError(
OPERATION,
{
cause,
conformsToInputContract: true,
remediationAction:
"Select the native binary and global-metadata.dat from the same build. If they are from the same build, either file may be damaged or the binary's registration layout may be outside coverage. Without the binary, the metadata alone can still be read.",
},
[
{
path: ["path"],
reason: "invalid_value",
message: `Selected metadata ${metadataPath} does not link to the selected binary: ${cause.message}`,
},
{
path: ["binary_path"],
reason: "invalid_value",
message: `Selected binary ${binaryPath} does not link to the metadata: ${cause.message}`,
},
],
);
const failureForPrimary = (
facts: ArtifactFilePrimaryFacts,
path: string,
@@ -103,27 +138,20 @@ const failureForPrimary = (
),
);
if (
cause instanceof Il2cppBinaryFormatFailure ||
cause instanceof Il2cppMetadataFormatFailure
) {
const binary = cause instanceof Il2cppBinaryFormatFailure;
// Metadata names are read on demand while linking, so a metadata failure
// can surface while path still names the binary.
const target = binary ? path : metadataPath;
return cause.kind === "unsupported"
? new AnalysisUnsupportedTargetError(OPERATION, target, cause.message, {
cause,
})
: new AnalysisInputError(OPERATION, { cause }, [
{
path: [binary ? field : "path"],
reason: "invalid_format",
message: binary
? `Selected binary ${target} does not link to the metadata: ${cause.message}`
: `Selected artifact ${target} is corrupt: ${cause.message}`,
},
]);
}
cause instanceof Il2cppBinaryFormatFailure &&
isIl2cppLinkConflict(cause.reason)
)
return linkConflict(path, metadataPath, cause);
// Each file's own format failure names that file. Metadata names are read
// on demand while linking, so a metadata failure can surface while `path`
// here still names the binary.
const ownFormatFailure =
cause instanceof Il2cppBinaryFormatFailure
? parseFailureAnalysisError(OPERATION, path, cause)
: cause instanceof Il2cppMetadataFormatFailure
? parseFailureAnalysisError(OPERATION, metadataPath, cause)
: undefined;
if (ownFormatFailure !== undefined) return ownFormatFailure;
const identityFailure = projectOwnedArtifactIdentityFailure(
facts,
OPERATION,