Skip to content

Bugfix for incorrect parameters seen in br_table and end hooks#50

Merged
danleh merged 1 commit into
danleh:masterfrom
Chadderz121:bugfix-br_table-index
Jan 28, 2026
Merged

Bugfix for incorrect parameters seen in br_table and end hooks#50
danleh merged 1 commit into
danleh:masterfrom
Chadderz121:bugfix-br_table-index

Conversation

@Chadderz121

Copy link
Copy Markdown
Contributor

A concurrency bug can corrupt the output in large wasm files containing many br_table instructions when end or br_table hooks are enabled. This leads to incorrect information being passed to the hook for br_table instructions, or end instructions if the output happens to be corrupted. In a large example benchmark with more than 200 functions and more than 50 br_table instructions, this meant that the output was always wrong.

The bug is caused because the br_tables vector can be modified concurrently. A reader/writer lock correctly protects this, however, the lock is dropped briefly between adding a new item and calculating the new item's index. This therefore allows a race condition in which another writer modifies the vector before the index is calculated. This fix holds the lock whilst the index is calculated.

The br_tables vector can be modified concurrently. A reader/writer lock
correctly protects this, however, the lock is dropped briefly between adding a
new item and calculating the new item's index. This therefore allows a race
condition in which another writer modifies the vector before the index is
calculated. This fix holds the lock whilst the index is calculated.

@danleh danleh left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, nice find. Thanks!

@danleh
danleh merged commit 8af394a into danleh:master Jan 28, 2026
0 of 4 checks passed
@Chadderz121
Chadderz121 deleted the bugfix-br_table-index branch January 29, 2026 10:08
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.

2 participants