Skip to content

Foreign effect IDs resolve only in the owner's import scope (#1045) - #1095

Closed
oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/effect-cid-namespace
Closed

oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/effect-cid-namespace

Conversation

@oxura

@oxura oxura commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Closes #1045.

A later entry declaration could take a sibling foreign file’s CID(None) or CID(Con) by spelling the sibling’s canonical namespace. The C lane could then treat the returned tag as a value of the wrong allocation size. Foreign CID/FID substitution now accepts local names only from the effect owner’s source and fallback names only from files loaded before that owner (its imports). The generated runtime’s own IDs are unchanged. Unknown names fail rather than bind to later entry declarations.

tests/io/cid_capture.bend imports a trusted sibling under another alias, forges both None and a three-field Con, consumes the Maybe result, and drops the List result. Before the fix interpreted JS printed Some instead of None; after it, interpreted JS, emitted JS and native C print None / 6. The native regression also ran under AddressSanitizer without a report. An existing imported effect with module-local constructors (marshal_imported_nullary) still runs on JS and C. bun gates/repo.ts: PASS 46/46. Cluster and macOS not run.

@nicolas-abril

Copy link
Copy Markdown
Collaborator

Thanks for the careful report and fix. The root cause turned out to be the key encoding rather than c_ids: a namespace joined its names with ., so the entry's declaration lib.None took the same key as lib.bend's own None. #1156 joins namespaces with /, which no name can contain, so that collision can't happen. c_ids then needs no scope sets, and parse_reso is covered too. Your tests/io/cid_capture regression test is in #1156 as it was, with you credited as co-author. Closing in favour of #1156.


This comment was written with AI assistance (Claude Code) and checked by me.

nicolas-abril added a commit that referenced this pull request Sep 28, 2026
…file's namespace and a foreign CID(None) keeps meaning Base's None (#1045)

A file's names were keyed namespace + "." + name, and the entry file,
whose namespace is "", keys its names bare. So the entry's declaration
lib.None took the key lib.bend's own None would have had, and lib.bend's
foreign C and JS, whose CID(k) tries lib.k before k once every file has
loaded, returned the entry's constructor where lib.bend meant Base's
None: the wrong match arm, and on C a read of the allocator's bump word
and a free into the wrong size class.

The namespace now joins its names with ":", which neither a name nor a
path holds, so a key names its file: lib.bend's None is lib:None, and
the entry's lib.None stays lib.None. An alias expands to ns:name, c_ids
tries ns:k then k, and name_show splits a key at its ":". A key no alias
reaches is shown as it is (sub/deep:Box); the unsafe list says
unsafe_lib:boom.

The entry may now declare lib.x beside lib.bend's x, a file may be named
like a Base type (U32.bend with show) or declare its own name (lib.bend
with lib.lib), and a file reaches another's names only through its
aliases.

tests/io/cid_capture is from #1095: a forged None and a three-field Con
over a List node print None and 6 on every lane.

Co-authored-by: oxura <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
nicolas-abril added a commit that referenced this pull request Sep 28, 2026
…on lands in another file's namespace and a foreign CID(None) keeps meaning Base's None (#1045)

A file's names were keyed namespace + "." + name, and the entry file,
whose namespace is "", keys its names bare. So the entry's declaration
lib.None took the key lib.bend's own None would have had, and lib.bend's
foreign C and JS, whose CID(k) tries lib.k before k once every file has
loaded, returned the entry's constructor where lib.bend meant Base's
None: the wrong match arm, and on C a read of the allocator's bump word
and a free into the wrong size class.

A key now joins its namespace with ":", which neither a name nor a path
holds, so a key names its file: lib.bend's None is lib:None, and the
entry's lib.None stays lib.None. An alias expands to ns:name, c_ids
tries ns:k then k, and name_show splits a key at its ":".

The ":" never leaves the compiler: name_key spells ns:name as ns.name
wherever a key is written out (messages, the unsafe lists, a printed
main, JS tags, effect ids and exports, SHOW_NAMES, BendTT names), so
every output reads as before.

The entry may now declare lib.x beside lib.bend's x, a file may be named
like a Base type (U32.bend with show) or declare its own name (lib.bend
with lib.lib), and a file reaches another's names only through its
aliases.

tests/io/cid_capture is from #1095: a forged None and a three-field Con
over a List node print None and 6 on every lane.

Co-authored-by: oxura <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
nicolas-abril added a commit that referenced this pull request Oct 1, 2026
…on lands in another file's namespace and a foreign CID(None) keeps meaning Base's None (#1045)

A file's names were keyed namespace + "." + name, and the entry file,
whose namespace is "", keys its names bare. So the entry's declaration
lib.None took the key lib.bend's own None would have had, and lib.bend's
foreign C and JS, whose CID(k) tries lib.k before k once every file has
loaded, returned the entry's constructor where lib.bend meant Base's
None: the wrong match arm, and on C a read of the allocator's bump word
and a free into the wrong size class.

A key now joins its namespace with ":", which neither a name nor a path
holds, so a key names its file: lib.bend's None is lib:None, and the
entry's lib.None stays lib.None. An alias expands to ns:name, c_ids
tries ns:k then k, and name_show splits a key at its ":".

The ":" never leaves the compiler: name_key spells ns:name as ns.name
wherever a key is written out (messages, the unsafe lists, a printed
main, JS tags, effect ids and exports, SHOW_NAMES, BendTT names), so
every output reads as before.

The entry may now declare lib.x beside lib.bend's x, a file may be named
like a Base type (U32.bend with show) or declare its own name (lib.bend
with lib.lib), and a file reaches another's names only through its
aliases.

tests/io/cid_capture is from #1095: a forged None and a three-field Con
over a List node print None and 6 on every lane.

Co-authored-by: oxura <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
nicolas-abril added a commit that referenced this pull request Oct 1, 2026
…on lands in another file's namespace and a foreign CID(None) keeps meaning Base's None (#1045)

A file's names were keyed namespace + "." + name, and the entry file,
whose namespace is "", keys its names bare. So the entry's declaration
lib.None took the key lib.bend's own None would have had, and lib.bend's
foreign C and JS, whose CID(k) tries lib.k before k once every file has
loaded, returned the entry's constructor where lib.bend meant Base's
None: the wrong match arm, and on C a read of the allocator's bump word
and a free into the wrong size class.

A key now joins its namespace with ":", which neither a name nor a path
holds, so a key names its file: lib.bend's None is lib:None, and the
entry's lib.None stays lib.None. An alias expands to ns:name, c_ids
tries ns:k then k, and name_show splits a key at its ":".

The ":" never leaves the compiler: name_key spells ns:name as ns.name
wherever a key is written out (messages, the unsafe lists, a printed
main, JS tags, effect ids and exports, SHOW_NAMES, BendTT names), so
every output reads as before.

The entry may now declare lib.x beside lib.bend's x, a file may be named
like a Base type (U32.bend with show) or declare its own name (lib.bend
with lib.lib), and a file reaches another's names only through its
aliases.

tests/io/cid_capture is from #1095: a forged None and a three-field Con
over a List node print None and 6 on every lane.

Co-authored-by: oxura <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An entry declaration can hijack a sibling effect's CID and corrupt native runtime memory

2 participants