fix(artifacts): preserve ZIP identities and partial managed metadata
Reject malformed UTF-8 ZIP filenames at the decoding boundary while retaining CP437, Unicode Path overrides and leading U+FEFF. Preserve valid CustomAttribute parent and value facts when constructor identity is invalid, with an explicit partial-coverage issue. Validated ZIP integrity and filesystem-provider workflows, managed producer cases, temporary-file hygiene, package and static checks. Removed the superseded producer-only invalid-constructor regression.
This commit is contained in:
@@ -66,6 +66,7 @@ describe("managed artifact failure classification", () => {
|
||||
"System.Runtime",
|
||||
"System.Runtime",
|
||||
]);
|
||||
expect(artifact.attributes).toEqual([]);
|
||||
expect(artifact.coverage.issues.map(({ code }) => code)).toEqual(
|
||||
issueCodes,
|
||||
);
|
||||
|
||||
@@ -177,36 +177,29 @@ describe("managed artifact coded indexes", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("reports an invalid CustomAttribute constructor coded index", () => {
|
||||
const bytes = buildManagedPeFixture({ customAttributeTypeRaw: 19 });
|
||||
const result = inspectManagedArtifactBytes(
|
||||
bytes,
|
||||
managedPeFixtureTarget(bytes),
|
||||
);
|
||||
|
||||
expect(result.attributes).toEqual([]);
|
||||
expect(result.coverage).toMatchObject({
|
||||
state: "partial",
|
||||
issues: [
|
||||
expect.objectContaining({
|
||||
code: "invalid-row",
|
||||
scope: "metadata.CustomAttribute:0x0c000001",
|
||||
detail: expect.stringContaining(
|
||||
"coded index 0x13 is invalid: coded index selects row 2 in table 10, which has 1 rows",
|
||||
),
|
||||
}),
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("reports null for the required CustomAttribute constructor coded index", () => {
|
||||
const bytes = buildManagedPeFixture({ customAttributeTypeRaw: 0 });
|
||||
const result = inspectManagedArtifactBytes(
|
||||
bytes,
|
||||
managedPeFixtureTarget(bytes),
|
||||
);
|
||||
const text = Buffer.from(".NETCoreApp,Version=v8.0", "utf8");
|
||||
const attributeValue = Buffer.concat([
|
||||
Buffer.from([1, 0, text.length]),
|
||||
text,
|
||||
Buffer.alloc(2),
|
||||
]);
|
||||
|
||||
expect(result.attributes).toEqual([]);
|
||||
expect(result.attributes).toMatchObject([
|
||||
{
|
||||
parent_token: "0x20000001",
|
||||
constructor_token: null,
|
||||
type_name: null,
|
||||
value_length: attributeValue.length,
|
||||
value_sha256: createHash("sha256").update(attributeValue).digest("hex"),
|
||||
token: "0x0c000001",
|
||||
},
|
||||
]);
|
||||
expect(result.coverage).toMatchObject({
|
||||
state: "partial",
|
||||
issues: [
|
||||
@@ -227,7 +220,7 @@ describe("managed artifact coded indexes", () => {
|
||||
const bytes = buildManagedPeFixture({
|
||||
references,
|
||||
extendsRaw: 9,
|
||||
customAttributeTypeRaw: 19,
|
||||
customAttributeTypeRaw: 0,
|
||||
});
|
||||
const layout = metadataLayoutFor(bytes);
|
||||
const artifact = inspectManagedArtifactBytes(
|
||||
|
||||
@@ -27,6 +27,13 @@ type AssemblyReference = ManagedArtifactInspection["references"][number];
|
||||
type ManagedResource = ManagedArtifactInspection["resources"][number];
|
||||
type CustomAttribute = ManagedArtifactInspection["attributes"][number];
|
||||
|
||||
const HAS_CUSTOM_ATTRIBUTE_TABLES = [
|
||||
6, 4, 1, 2, 8, 9, 10, 0, 14, 23, 20, 17, 26, 27, 32, 35, 38, 39, 40, 42, 44,
|
||||
43,
|
||||
] as const;
|
||||
|
||||
const CUSTOM_ATTRIBUTE_TYPE_TABLES = [undefined, undefined, 6, 10] as const;
|
||||
|
||||
const publicKeyIdentity = (
|
||||
bytes: Buffer,
|
||||
kind: "public-key" | "public-key-token",
|
||||
@@ -360,56 +367,56 @@ export const readCustomAttribute = (
|
||||
const parent = metadataCodedToken(
|
||||
parentRaw,
|
||||
5,
|
||||
[
|
||||
6, 4, 1, 2, 8, 9, 10, 0, 14, 23, 20, 17, 26, 27, 32, 35, 38, 39, 40, 42,
|
||||
44, 43,
|
||||
],
|
||||
HAS_CUSTOM_ATTRIBUTE_TABLES,
|
||||
layout.rowCounts,
|
||||
);
|
||||
const parentReason = metadataCodedTokenInvalidReason(
|
||||
parentRaw,
|
||||
5,
|
||||
[
|
||||
6, 4, 1, 2, 8, 9, 10, 0, 14, 23, 20, 17, 26, 27, 32, 35, 38, 39, 40, 42,
|
||||
44, 43,
|
||||
],
|
||||
layout.rowCounts,
|
||||
);
|
||||
if (parent === null)
|
||||
if (parent === null) {
|
||||
const parentReason = metadataCodedTokenInvalidReason(
|
||||
parentRaw,
|
||||
5,
|
||||
HAS_CUSTOM_ATTRIBUTE_TABLES,
|
||||
layout.rowCounts,
|
||||
);
|
||||
throw managedFailure(
|
||||
"invalid-row",
|
||||
`metadata.CustomAttribute:${metadataToken(12, row)}`,
|
||||
`CustomAttribute parent coded index 0x${parentRaw.toString(16)} is invalid${parentReason === null ? " because the required parent is null" : `: ${parentReason}`}`,
|
||||
cursor.start,
|
||||
);
|
||||
const typeReason = metadataCodedTokenInvalidReason(
|
||||
}
|
||||
const constructor = metadataCodedToken(
|
||||
typeRaw,
|
||||
3,
|
||||
[undefined, undefined, 6, 10],
|
||||
CUSTOM_ATTRIBUTE_TYPE_TABLES,
|
||||
layout.rowCounts,
|
||||
);
|
||||
if (typeReason !== null || typeRaw === 0)
|
||||
throw managedFailure(
|
||||
"invalid-row",
|
||||
`metadata.CustomAttribute:${metadataToken(12, row)}`,
|
||||
typeReason === null
|
||||
? "CustomAttribute constructor coded index 0x0 is null, but Type must reference a MethodDef or MemberRef row"
|
||||
: `CustomAttribute constructor coded index 0x${typeRaw.toString(16)} is invalid: ${typeReason}`,
|
||||
typeOffset,
|
||||
);
|
||||
const typeName =
|
||||
readManagedValue(
|
||||
() => attributeTypeName(bytes, layout, typeRaw, heapExtent),
|
||||
issues,
|
||||
) ?? null;
|
||||
return {
|
||||
parent_token: parent,
|
||||
constructor_token: metadataCodedToken(
|
||||
if (constructor === null) {
|
||||
const typeReason = metadataCodedTokenInvalidReason(
|
||||
typeRaw,
|
||||
3,
|
||||
[undefined, undefined, 6, 10],
|
||||
CUSTOM_ATTRIBUTE_TYPE_TABLES,
|
||||
layout.rowCounts,
|
||||
),
|
||||
);
|
||||
issues.push({
|
||||
code: "invalid-row",
|
||||
scope: `metadata.CustomAttribute:${metadataToken(12, row)}`,
|
||||
offset: typeOffset,
|
||||
detail:
|
||||
typeReason === null
|
||||
? "CustomAttribute constructor coded index 0x0 is null, but Type must reference a MethodDef or MemberRef row"
|
||||
: `CustomAttribute constructor coded index 0x${typeRaw.toString(16)} is invalid: ${typeReason}`,
|
||||
});
|
||||
}
|
||||
let typeName: string | null = null;
|
||||
if (constructor !== null)
|
||||
typeName =
|
||||
readManagedValue(
|
||||
() => attributeTypeName(bytes, layout, typeRaw, heapExtent),
|
||||
issues,
|
||||
) ?? null;
|
||||
return {
|
||||
parent_token: parent,
|
||||
constructor_token: constructor,
|
||||
type_name: typeName,
|
||||
value_length: value.length,
|
||||
value_sha256: managedDecodeBudget(layout).digest(value, "sha256"),
|
||||
|
||||
Reference in New Issue
Block a user