Skip to content

Fix BEAM process crash on nested empty map property enumeration#8

Merged
dannote merged 1 commit into
elixir-volt:masterfrom
Lambdo-Labs:fix/empty-nested-beam-proxy
Apr 23, 2026
Merged

Fix BEAM process crash on nested empty map property enumeration#8
dannote merged 1 commit into
elixir-volt:masterfrom
Lambdo-Labs:fix/empty-nested-beam-proxy

Conversation

@andr-ec
Copy link
Copy Markdown
Contributor

@andr-ec andr-ec commented Apr 23, 2026

Fixes #7

beam_proxy.get_own_property_names calls js_malloc(ctx, 0) when the BEAM map is empty and has no overrides, hitting QuickJS's assert(size != 0). Return early with empty results when total == 0.

Change

lib/quickbeam/beam_proxy.zig — 4 lines added:

const total = map_size + override_count;
if (total == 0) {
    ptab.* = null;
    plen.* = 0;
    return 0;
}

Test

test/core/beam_proxy_empty_map_test.exs — 3 cases: Object.keys, for...in on nested empty map, plus non-empty control.

beam_proxy.get_own_property_names calls js_malloc(ctx, 0) when the
BEAM map is empty and has no overrides, hitting QuickJS's
assert(size != 0). Return early with empty results when total == 0.

Accessing a nested empty map via Object.keys or for...in
(e.g. QuickBEAM.call(rt, "fn", [%{x: %{}}])) crashed the entire
BEAM process. Top-level empty maps were unaffected.
dannote added a commit that referenced this pull request Apr 23, 2026
Fix BEAM crash on nested empty map property enumeration
@dannote dannote merged commit 2429642 into elixir-volt:master Apr 23, 2026
@dannote
Copy link
Copy Markdown
Member

dannote commented Apr 23, 2026

Thanks for the fix! Merged with one additional change on top: convertValue now also skips proxy creation for empty maps (matching the existing guard in beam_to_js.convert_map), so they never become proxies in the first place. Your defensive check in get_own_property_names is kept as a belt-and-suspenders guard.

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.

BEAM process crashes when enumerating keys of a nested empty map proxy

2 participants