-
Notifications
You must be signed in to change notification settings - Fork 5
feat(ocap-kernel): Prevent overriding endowment names #619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
88f8f25
to
5017064
Compare
d3d2a33
to
e84ffcd
Compare
e84ffcd
to
199d7e3
Compare
for (const obj of objects) { | ||
for (const key of Reflect.ownKeys(obj)) { | ||
if (keys.has(key)) { | ||
const originalIndex = keys.get(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (const obj of objects) { | |
for (const key of Reflect.ownKeys(obj)) { | |
if (keys.has(key)) { | |
const originalIndex = keys.get(key); | |
objects.forEach((obj, originalIndex) => { | |
for (const key of Reflect.ownKeys(obj)) { | |
if (keys.has(key)) { |
I guess this is simpler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no you are using the collidingIndex. But I'm not so sure why we need that and not simply do something like
const seen = new Map<PropertyKey, number>();
const out: Record<PropertyKey, unknown> = Object.create(null);
objects.forEach((obj, idx) => {
for (const key of Reflect.ownKeys(obj)) {
if (seen.has(key)) {
throw new Error(
`Duplicate key "${String(key)}" found in entries ${seen.get(key)} and ${idx}`
);
}
seen.set(key, idx);
}
Object.defineProperties(out, Object.getOwnPropertyDescriptors(obj));
});
return out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case the index is used to differentiate between an internal error and a user error where the VatSupervisor uses the function.
650c260
to
996a6f3
Compare
}; | ||
throw new DuplicateEndowmentError(String(key), collidingIndex === 1); | ||
} | ||
// Otherwise, just rethrow the error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Endowment Collision Classification Error
The DuplicateEndowmentError.isInternal
flag is incorrectly determined. It currently only checks if collidingIndex === 1
, which misclassifies internal endowment collisions. Since workerEndowments
, platformEndowments
, and lsEndowments
are all internal sources, any collision between them should be marked as internal. The classification needs to consider both originalIndex
and collidingIndex
to accurately reflect internal conflicts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR ensures that the various sources of vat namespace endowments do not provide colliding names, causing the VatSupervisor to throw an error instead in this case.