Files
rea/src/il2cpp/Il2cppBinaryFormat.ts
T
morluto 57f4e3c4bd 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.
2026-11-23 20:23:19 -05:00

111 lines
3.7 KiB
TypeScript

import { ParseFailureError } from "../domain/parseFailure.js";
/** Existing selected-binary allowance also bounds its retained pointer workspace. */
export const IL2CPP_BINARY_BYTES = 1024 * 1024 * 1024;
export const IL2CPP_BINARY_FAILURE_REASONS = {
unsupported: [
"unsupported-container",
"unsupported-pointer-encoding",
"unsupported-type-kind",
"generic-methods-unsupported",
],
capacity: [
"native-index-capacity",
"type-nesting-capacity",
"native-type-text-capacity",
],
/** 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",
"invalid-method-pointer",
"invalid-method-token",
"metadata-registration-not-found",
"invalid-type",
"generic-method-registration-not-found",
"ambiguous-generic-method-registration",
],
} as const;
export type Il2cppBinaryFailureReason =
(typeof IL2CPP_BINARY_FAILURE_REASONS)[keyof typeof IL2CPP_BINARY_FAILURE_REASONS][number];
/** A named workspace budget; the parse stopped without showing the input invalid. */
export type Il2cppBinaryCapacityReason =
(typeof IL2CPP_BINARY_FAILURE_REASONS.capacity)[number];
type Il2cppBinaryFormatReason = Exclude<
Il2cppBinaryFailureReason,
Il2cppBinaryCapacityReason
>;
/** What a native-link budget counts, so its maximum is reported with its unit. */
export type NativeBudgetUnit = "entries" | "bytes" | "frames";
/** The ParseFailure format of a native image linked against IL2CPP metadata. */
export const IL2CPP_BINARY_FORMAT = "il2cpp-binary";
const isUnsupported = (reason: Il2cppBinaryFormatReason) =>
(IL2CPP_BINARY_FAILURE_REASONS.unsupported as readonly string[]).includes(
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
* reason is a ParseFailure `limit` carrying the exceeded maximum.
*/
export class Il2cppBinaryFormatFailure extends ParseFailureError<
"malformed" | "unsupported" | "limit"
> {
/** What the exceeded maximum counts; set only for a capacity reason. */
readonly unit: NativeBudgetUnit | undefined;
constructor(reason: Il2cppBinaryFormatReason, message: string);
constructor(
reason: Il2cppBinaryCapacityReason,
message: string,
maximum: number,
unit: NativeBudgetUnit,
);
constructor(
readonly reason: Il2cppBinaryFailureReason,
message: string,
maximum?: number,
unit?: NativeBudgetUnit,
) {
const detail = `${reason}: ${message}`;
super(
maximum !== undefined
? {
kind: "limit",
format: IL2CPP_BINARY_FORMAT,
detail,
limit: { name: reason, maximum },
}
: isUnsupported(reason as Il2cppBinaryFormatReason)
? {
kind: "unsupported",
format: IL2CPP_BINARY_FORMAT,
detail,
undecodedContent: false,
}
: { kind: "malformed", format: IL2CPP_BINARY_FORMAT, detail },
);
this.unit = unit;
this.name = "Il2cppBinaryFormatFailure";
}
}