Skip to content

Reject hamt duplications in enif_make_map_from_arrays#10976

Open
nickva wants to merge 2 commits intoerlang:masterfrom
nickva:maint-fix-maps-from-arr
Open

Reject hamt duplications in enif_make_map_from_arrays#10976
nickva wants to merge 2 commits intoerlang:masterfrom
nickva:maint-fix-maps-from-arr

Conversation

@nickva
Copy link
Copy Markdown
Contributor

@nickva nickva commented Apr 6, 2026

Previously enif_make_map_from_arrays did not reject duplicates for hamt maps (those with greater than 32 keys) as the API indicated. Instead, it would return a hamt map that might not match against a map built from the same key-value pair set in Erlang.

It turns out that the internal hamt building call already takes a reject_dupkeys argument, it was just always set to 0, so to fix the issue we thread the parameter through, so that enif_make_map_from_arrays when it constructs the hamt object, always sets reject_dupkeys=1.

Fix #10975

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

CT Test Results

    3 files    136 suites   50m 46s ⏱️
1 675 tests 1 619 ✅ 56 💤 0 ❌
2 317 runs  2 243 ✅ 74 💤 0 ❌

Results for commit a52bc0f.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@rickard-green rickard-green added the team:VM Assigned to OTP team VM label Apr 7, 2026
@sverker
Copy link
Copy Markdown
Contributor

sverker commented Apr 13, 2026

Thanks for the report and fix. I pushed a fixup that instead makes erts_map_from_ks_and_vs consistent and always reject duplicates regardless of map size.

nickva and others added 2 commits April 13, 2026 19:15
Previously `enif_make_map_from_arrays` did not reject duplicates for hamt
maps (those with greater than 32 keys) as the API indicated. Intead, it would
return a hamt map that might not match against a map built from the same
key-value pairs in Erlang.

It turns out that the internal hamt building call already takes a
`reject_dupkeys` argument, it was just always set to 0, so to fix the issue, we
thread the parameter through, so that `enif_make_map_from_arrays` when it
constructs the hamt object, always sets `reject_dupkeys=1`.

Fix erlang#10975

Co-authored-by: Sverker Eriksson <sverker@erlang.org>
into 'sverker/27/erts/fix-nif-map-from-array/OTP-20098'
@nickva
Copy link
Copy Markdown
Contributor Author

nickva commented Apr 13, 2026

Thank you, Sverker, that's a much better fix!

@sverker sverker force-pushed the maint-fix-maps-from-arr branch from a15f671 to a52bc0f Compare April 13, 2026 18:08
@sverker
Copy link
Copy Markdown
Contributor

sverker commented Apr 13, 2026

I squashed our two commits and rebased it back onto patch-base-26 with a forward merge to patch-base-27 to solve a conflict. Now the same fix can be released on 26, 27, 28 and 29.

@sverker sverker added the testing currently being tested, tag is used by OTP internal CI label Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid maps from enif_make_map_from_arrays

3 participants