Skip to content

Fix buffer overflow for arity > 16 in Nary ops#19

Open
a2435191 wants to merge 2 commits into
harmonylang:masterfrom
a2435191:nary-arity-bug-fix
Open

Fix buffer overflow for arity > 16 in Nary ops#19
a2435191 wants to merge 2 commits into
harmonylang:masterfrom
a2435191:nary-arity-bug-fix

Conversation

@a2435191
Copy link
Copy Markdown

Overview

Currently, an n-ary operation with n > 16 overflows a buffer.

# More than 16 arity causes an unhandled crash
y = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17

Changes Made

I updated the compiler with an assert in the constructor of NaryOp and a graceful compiler error in the one place where the arity isn't known. Since it seems bad to just trust the HVM output, I also added a check in init_Nary in ops.c, where the JSON data is loaded, and finally an assert right before the place where the buffer overflow actually happened in op_Nary.

Crash log

Test Coverage

I tested the changes by selectively disabling some checks. I wasn't able to test the assert though.

Next Steps

Maybe the compiler could automatically split up ops with arity > 16.

@a2435191 a2435191 changed the title Check for arity <= 16 in Nary ops Fix buffer overflow for arity > 16 in Nary ops May 17, 2026
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.

1 participant