fix(managed): share first-match member ownership indexes

Resolve fields, methods, and attribute constructors through one budgeted index per layout. Preserve malformed-list first-match ownership without per-member TypeDef scans; remove the superseded lookup implementations.

Validate pointer identity and malformed ranges through production parsers, including a 40,000-type/method case and allocation admission. Managed source tests and CLI/MCP pointer acceptance pass. Refs #1953.
This commit is contained in:
morluto
2026-10-12 04:33:25 +08:00
parent 1449e8e051
commit 52e76c5d39
7 changed files with 259 additions and 267 deletions
+15 -18
View File
@@ -8,7 +8,6 @@ import type { ManagedPeLayout } from "./ManagedPeReader.js";
import type { ManagedParseIssue } from "../domain/managed/managedArtifact.js";
import type { ManagedMetadataLayout } from "./ManagedMetadataLayout.js";
import {
createDeclaringTypeLookup,
signature,
type FieldCore,
type ManagedCallEdge,
@@ -31,7 +30,7 @@ import {
} from "./ManagedMetadataHeaps.js";
import { readManagedValue } from "./ManagedReaderFailure.js";
import { methodBody } from "./ManagedMethodBodyReader.js";
import { memberListRowLookup } from "./ManagedMemberPointers.js";
import { memberDeclaringTypeRowLookup } from "./ManagedMemberOwnership.js";
export const parseFields = (
bytes: Buffer,
@@ -46,9 +45,8 @@ export const parseFields = (
const core = new Map<string, FieldCore>();
const issues: ManagedParseIssue[] = [];
const table = layout.table(4);
const declaringType = createDeclaringTypeLookup(ranges, "field");
const listRow = readManagedValue(
() => memberListRowLookup(bytes, layout, 4),
const ownerRow = readManagedValue(
() => memberDeclaringTypeRowLookup(bytes, layout, 4),
issues,
);
for (let row = 1; row <= (table?.rowCount ?? 0); row += 1) {
@@ -67,11 +65,11 @@ export const parseFields = (
cursor.readIndex(layout.blobIndexSize),
layout.blob.size,
);
const position =
listRow === undefined
? undefined
: readManagedValue(() => listRow(row), issues);
const declared = position === undefined ? null : declaringType(position);
const owner =
ownerRow === undefined
? 0
: (readManagedValue(() => ownerRow(row), issues) ?? 0);
const declared = ranges[owner - 1];
const token = metadataToken(4, row);
fields.push({
token,
@@ -245,9 +243,8 @@ export const parseMethods = ({
const core = new Map<string, MethodCore>();
const issues: ManagedParseIssue[] = [];
const table = layout.table(6);
const declaringType = createDeclaringTypeLookup(ranges, "method");
const listRow = readManagedValue(
() => memberListRowLookup(bytes, layout, 6),
const ownerRow = readManagedValue(
() => memberDeclaringTypeRowLookup(bytes, layout, 6),
issues,
);
for (let row = 1; row <= (table?.rowCount ?? 0); row += 1) {
@@ -269,11 +266,11 @@ export const parseMethods = ({
layout.blob.size,
);
cursor.readIndex(layout.tableIndexSize(8));
const position =
listRow === undefined
? undefined
: readManagedValue(() => listRow(row), issues);
const declared = position === undefined ? null : declaringType(position);
const owner =
ownerRow === undefined
? 0
: (readManagedValue(() => ownerRow(row), issues) ?? 0);
const declared = ranges[owner - 1];
const token = metadataToken(6, row);
methods.push({
token,