fix(dotnet): downgrade truncated CIL identity and coverage

This commit is contained in:
N0zoM1z0
2026-07-17 20:26:22 +08:00
parent 1387be08dd
commit dae6807c4a
44 changed files with 312 additions and 105 deletions
+1 -1
View File
@@ -162,7 +162,7 @@ const managedInstructionAnchorSchema = z.object({
});
const managedMethodBodySchema = z.object({
status: z.enum(["present", "absent", "malformed", "too-large"]),
status: z.enum(["present", "partial", "absent", "malformed", "too-large"]),
header_format: z.enum(["tiny", "fat", "none", "unknown"]),
rva: z.number().int().min(0).max(0xffff_ffff),
file_offset: offsetSchema.nullable(),
+31 -24
View File
@@ -190,7 +190,7 @@ export interface ManagedMemberComparisonSide {
interface Keyed<Item> {
readonly item: Item;
readonly exactKey: string | null;
readonly structuralKey: string;
readonly structuralKey: string | null;
}
interface MatchedPair<Item> {
@@ -335,6 +335,7 @@ const keyMethod = (item: Method): Keyed<Method> => ({
item,
exactKey:
item.signature.parse_status === "decoded" &&
item.body.status === "present" &&
item.body.normalized_il_sha256 !== null
? stableKey([
"method-exact",
@@ -342,29 +343,35 @@ const keyMethod = (item: Method): Keyed<Method> => ({
item.body.normalized_il_sha256,
])
: null,
structuralKey: stableKey([
"method-structural",
item.signature.kind,
item.signature.calling_convention,
item.signature.generic_parameter_count,
item.signature.parameter_count,
item.signature.return_type,
item.signature.parameter_types,
item.body.status,
item.body.header_format,
item.body.il_size,
item.body.max_stack,
item.body.init_locals,
item.body.opcode_counts,
item.body.anchors.map(({ opcode, operand_kind }) => [opcode, operand_kind]),
item.body.exception_regions.map((region) => [
region.flags,
region.try_length,
region.handler_length,
region.class_token === null ? null : "type-token",
region.filter_offset === null ? null : "filter",
]),
]),
structuralKey:
item.body.status === "present"
? stableKey([
"method-structural",
item.signature.kind,
item.signature.calling_convention,
item.signature.generic_parameter_count,
item.signature.parameter_count,
item.signature.return_type,
item.signature.parameter_types,
item.body.status,
item.body.header_format,
item.body.il_size,
item.body.max_stack,
item.body.init_locals,
item.body.opcode_counts,
item.body.anchors.map(({ opcode, operand_kind }) => [
opcode,
operand_kind,
]),
item.body.exception_regions.map((region) => [
region.flags,
region.try_length,
region.handler_length,
region.class_token === null ? null : "type-token",
region.filter_offset === null ? null : "filter",
]),
])
: null,
});
const keyField = (item: Field): Keyed<Field> => ({
+3
View File
@@ -136,6 +136,9 @@ export const importManagedReconstruction = (
(item) =>
item.token === candidate.token &&
item.signature.raw_sha256 === candidate.signature_sha256 &&
item.body.status === "present" &&
item.body.normalized_il_sha256 !== null &&
candidate.normalized_il_sha256 !== null &&
item.body.normalized_il_sha256 === candidate.normalized_il_sha256,
);
if (observed === undefined)
+10 -1
View File
@@ -84,7 +84,13 @@ export const managedRuntimeCorrelationResultSchema = z.strictObject({
normalized_il_sha256: digestSchema.nullable(),
body_sha256: digestSchema.nullable(),
il_size: z.number().int().min(0),
body_status: z.enum(["present", "absent", "malformed", "too-large"]),
body_status: z.enum([
"present",
"partial",
"absent",
"malformed",
"too-large",
]),
exact_build_required: z.literal(true),
}),
requested_runtime: z.strictObject({
@@ -138,6 +144,9 @@ export const planManagedRuntimeCorrelation = (
(item) =>
item.token === input.method.token &&
item.signature.raw_sha256 === input.method.signature_sha256 &&
item.body.status === "present" &&
item.body.normalized_il_sha256 !== null &&
input.method.normalized_il_sha256 !== null &&
item.body.normalized_il_sha256 === input.method.normalized_il_sha256,
);
if (method === undefined)
+37 -5
View File
@@ -1080,8 +1080,14 @@ const methodBody = (
);
const methodEnd = ilOffset + header.ilSize;
const sectionOffset = (methodEnd + 3) & ~3;
const status =
decoded.issue !== null
? "malformed"
: decoded.truncated > 0
? "partial"
: "present";
return {
status: decoded.issue === null ? "present" : "malformed",
status,
header_format: header.format,
rva,
file_offset: offset,
@@ -1093,7 +1099,8 @@ const methodBody = (
: `0x${header.localSig.toString(16).padStart(8, "0")}`,
il_size: header.ilSize,
il_sha256: sha256Bytes(il),
normalized_il_sha256: sha256Bytes(normalized),
normalized_il_sha256:
status === "present" ? sha256Bytes(normalized) : null,
instruction_count: decoded.count,
decoded_instruction_count: decoded.parsed.length,
truncated_instructions: decoded.truncated,
@@ -1103,7 +1110,11 @@ const methodBody = (
header.format === "fat" && (header.flags & 8) !== 0
? parseExceptionRegions(bytes, sectionOffset, bytes.length)
: [],
issue: decoded.issue,
issue:
decoded.issue ??
(decoded.truncated > 0
? `Instruction decode reached max_method_instructions ${String(limits.maxMethodInstructions)} before the end of the method body`
: null),
};
} catch (cause: unknown) {
return {
@@ -1436,6 +1447,22 @@ export const inspectManagedMembersBytes = (
limits.maxHeapItemBytes,
limits,
);
const methodBodyIssues: ManagedParseIssue[] = methods.methods.flatMap(
(method) =>
method.body.status === "partial"
? [
{
code: "limit-exceeded" as const,
scope: `method.${method.token}.body.instructions`,
offset: method.body.file_offset,
detail:
method.body.issue ??
`Instruction decode reached max_method_instructions ${String(limits.maxMethodInstructions)}`,
},
]
: [],
);
const coverageIssues = [...issues, ...methodBodyIssues];
const related = edges(
methods.methods,
methods.core,
@@ -1476,13 +1503,18 @@ export const inspectManagedMembersBytes = (
limits.edgeLimit,
),
coverage: {
state: issues.length === 0 ? "complete" : "partial",
issues,
state: coverageIssues.length === 0 ? "complete" : "partial",
issues: coverageIssues,
},
limitations: [
"Metadata tokens are build-local coordinates and are only meaningful with the reported artifact SHA-256 and MVID.",
"CIL instruction anchors are decoded from file-backed method bodies only; no target assembly is loaded or executed.",
"Signatures are decoded for common ECMA-335 primitive, class, valuetype, pointer, byref, array, and generic variable forms; unsupported forms retain raw signature hashes.",
...(methodBodyIssues.length > 0
? [
"At least one CIL method body reached max_method_instructions; its decoded prefix is partial and has no normalized CIL identity.",
]
: []),
],
});
} catch (cause: unknown) {