mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 21:53:51 +00:00
fix(managed): refuse empty field definition identities (#12467)
This commit is contained in:
1 parent
5a62623cd1
commit
82fa175d2f
11 files changed
+217
-94
No files matched your search
@@ -2,6 +2,7 @@ import type { ManagedMetadataLayout } from "../domain/managed/managedMetadataLay
|
||||
import {
|
||||
metadataRowCursor,
|
||||
metadataToken,
|
||||
readRequiredMetadataName,
|
||||
} from "../domain/managed/managedMetadataHeaps.js";
|
||||
|
||||
/** Scalar Field facts; consumers own heap admission and field selection. */
|
||||
@@ -14,6 +15,7 @@ export const readFieldDefinitionRow = (
|
||||
readonly rowOffset: number;
|
||||
readonly flags: number;
|
||||
readonly nameIndex: number;
|
||||
readonly nameOffset: number;
|
||||
readonly signatureIndex: number;
|
||||
} => {
|
||||
// Layout admission bounds the complete row independently of its heap values.
|
||||
@@ -22,7 +24,24 @@ export const readFieldDefinitionRow = (
|
||||
token: metadataToken(4, row),
|
||||
rowOffset: cursor.start,
|
||||
flags: cursor.u16(),
|
||||
nameOffset: cursor.offset,
|
||||
nameIndex: cursor.readIndex(layout.stringIndexSize),
|
||||
signatureIndex: cursor.readIndex(layout.blobIndexSize),
|
||||
};
|
||||
};
|
||||
|
||||
export const readFieldDefinitionName = (
|
||||
bytes: Buffer,
|
||||
layout: ManagedMetadataLayout,
|
||||
definition: Pick<
|
||||
ReturnType<typeof readFieldDefinitionRow>,
|
||||
"token" | "nameIndex" | "nameOffset"
|
||||
>,
|
||||
): string =>
|
||||
readRequiredMetadataName(
|
||||
bytes,
|
||||
layout,
|
||||
"Field",
|
||||
definition.token,
|
||||
definition,
|
||||
);
|
||||
@@ -1,4 +1,7 @@
|
||||
import { readFieldDefinitionRow } from "./ManagedFieldDefinitionRows.js";
|
||||
import {
|
||||
readFieldDefinitionName,
|
||||
readFieldDefinitionRow,
|
||||
} from "./ManagedFieldDefinitionRows.js";
|
||||
import { createManagedFieldConstantReader } from "./ManagedFieldConstants.js";
|
||||
import { readMemberReferenceRowFacts } from "../domain/managed/managedMemberReferenceRows.js";
|
||||
import {
|
||||
@@ -111,9 +114,9 @@ export const parseFields = (
|
||||
)
|
||||
continue;
|
||||
readManagedValue(() => {
|
||||
const { token, rowOffset, flags, nameIndex, signatureIndex } =
|
||||
readFieldDefinitionRow(bytes, layout, row);
|
||||
const name = readMetadataString(bytes, layout, nameIndex);
|
||||
const definition = readFieldDefinitionRow(bytes, layout, row);
|
||||
const { token, rowOffset, flags, signatureIndex } = definition;
|
||||
const name = readFieldDefinitionName(bytes, layout, definition);
|
||||
const owned = owner ?? 0;
|
||||
core.set(token, {
|
||||
token,
|
||||
@@ -507,10 +510,10 @@ export const readReferencedMemberCores = (
|
||||
const declared = ranges[ownerOf(table, row) - 1];
|
||||
const name =
|
||||
table === 4
|
||||
? readMetadataString(
|
||||
? readFieldDefinitionName(
|
||||
bytes,
|
||||
layout,
|
||||
readFieldDefinitionRow(bytes, layout, row).nameIndex,
|
||||
readFieldDefinitionRow(bytes, layout, row),
|
||||
)
|
||||
: readMethodDefinitionName(
|
||||
bytes,
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { readFieldDefinitionRow } from "./ManagedFieldDefinitionRows.js";
|
||||
import {
|
||||
readFieldDefinitionName,
|
||||
readFieldDefinitionRow,
|
||||
} from "./ManagedFieldDefinitionRows.js";
|
||||
import {
|
||||
readMethodDefinitionName,
|
||||
readMethodDefinitionRow,
|
||||
@@ -94,12 +97,9 @@ export const parseFields = (
|
||||
const table = layout.table(4);
|
||||
for (let row = 1; row <= (table?.rowCount ?? 0); row += 1) {
|
||||
readManagedValue(() => {
|
||||
const { token, rowOffset, flags, nameIndex } = readFieldDefinitionRow(
|
||||
bytes,
|
||||
layout,
|
||||
row,
|
||||
);
|
||||
const name = readMetadataString(bytes, layout, nameIndex);
|
||||
const definition = readFieldDefinitionRow(bytes, layout, row);
|
||||
const { token, rowOffset, flags } = definition;
|
||||
const name = readFieldDefinitionName(bytes, layout, definition);
|
||||
fields.set(token, {
|
||||
token,
|
||||
rowOffset,
|
||||
|
||||
@@ -210,25 +210,36 @@ it.each([0, 2])(
|
||||
},
|
||||
);
|
||||
|
||||
it("reports field imports as declarations without inventing method implementations", () => {
|
||||
const bytes = buildManagedPeFixture({ pinvoke: { memberForwardedRaw: 2 } });
|
||||
const result = inspectManagedNativeBoundariesBytes(
|
||||
bytes,
|
||||
managedPeFixtureTarget(bytes),
|
||||
);
|
||||
expect(result.pinvoke_imports).toMatchObject([
|
||||
{
|
||||
member_kind: "field",
|
||||
member_token: "0x04000001",
|
||||
member_name: "counter",
|
||||
},
|
||||
]);
|
||||
expect(
|
||||
result.native_implementations.every((item) =>
|
||||
item.token.startsWith("0x06"),
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
it.each([
|
||||
{ fieldName: "counter", memberName: "counter", status: "complete" },
|
||||
{ fieldName: "", memberName: null, status: "partial" },
|
||||
])(
|
||||
"preserves a field import declaration with a $status FieldDef name observation",
|
||||
({ fieldName, memberName, status }) => {
|
||||
const bytes = buildManagedPeFixture({
|
||||
fieldName,
|
||||
pinvoke: { memberForwardedRaw: 2 },
|
||||
});
|
||||
const result = inspectManagedNativeBoundariesBytes(
|
||||
bytes,
|
||||
managedPeFixtureTarget(bytes),
|
||||
);
|
||||
expect(result.pinvoke_imports).toMatchObject([
|
||||
{
|
||||
member_kind: "field",
|
||||
member_token: "0x04000001",
|
||||
member_name: memberName,
|
||||
import_name: "MessageBoxW",
|
||||
},
|
||||
]);
|
||||
expect(result.metadata.status).toBe(status);
|
||||
expect(
|
||||
result.native_implementations.every((item) =>
|
||||
item.token.startsWith("0x06"),
|
||||
),
|
||||
).toBe(true);
|
||||
},
|
||||
);
|
||||
|
||||
describe("managed native boundary inspection", () => {
|
||||
it("reports absent or malformed member metadata", () => {
|
||||
|
||||
Reference in new issue
Block a user