Fix ArgumentOutOfRangeExecption with 0xffff parameters #977

Open
ItsZil wants to merge 1 commit from Unity-Technologies/proper-param0xffff-fix into master
ItsZil commented 2026-03-10 10:24:19 -05:00 (Migrated from github.com)

This PR fixes #913 and improves the original unmerged fix in PR #914.


The fix provided in PR #914 is insufficient in certain cases due to this condition:
current_index + 1 == current_table.Length

The above condition causes the fix to apply only when the overflow is on the second-to-last row of the method metadata table. But if there are additional parameterless methods at the end of the table, the parameter metadata table does not grow together with the method table. This causes the overflow to occur further from the end of the table.

The fix is simple: remove the above condition altogether. This is safe because next_index can never be 0 when the parameters table is exactly 0xffff.


Note that the same issue also applies to dnlib, as it also checks for tableSourceRid + 1 == tableSource.Rows.

I added a test which uses the same module as param0xffff.dll, but adds a couple of extra parameterless methods on top, which move the overflow away from the second-to-last row.

This PR fixes #913 and improves the original unmerged fix in PR #914. ___ The fix provided in PR #914 is insufficient in certain cases due to this condition: `current_index + 1 == current_table.Length` The above condition causes the fix to apply only when the overflow is on the second-to-last row of the method metadata table. But if there are additional parameterless methods at the end of the table, the parameter metadata table does not grow together with the method table. This causes the overflow to occur further from the end of the table. The fix is simple: remove the above condition altogether. This is safe because `next_index` can never be 0 when the parameters table is exactly `0xffff`. ___ Note that the same issue also applies to `dnlib`, as it also checks for `tableSourceRid + 1 == tableSource.Rows`. I added a test which uses the same module as param0xffff.dll, but adds a couple of extra parameterless methods on top, which move the overflow away from the second-to-last row.
This pull request is broken due to missing fork information.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'Unity-Technologies/proper-param0xffff-fix:Unity-Technologies/proper-param0xffff-fix'
git switch 'Unity-Technologies/proper-param0xffff-fix'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'master'
git merge --no-ff 'Unity-Technologies/proper-param0xffff-fix'
git switch 'Unity-Technologies/proper-param0xffff-fix'
git rebase 'master'
git switch 'master'
git merge --ff-only 'Unity-Technologies/proper-param0xffff-fix'
git switch 'Unity-Technologies/proper-param0xffff-fix'
git rebase 'master'
git switch 'master'
git merge --no-ff 'Unity-Technologies/proper-param0xffff-fix'
git switch 'master'
git merge --squash 'Unity-Technologies/proper-param0xffff-fix'
git switch 'master'
git merge --ff-only 'Unity-Technologies/proper-param0xffff-fix'
git switch 'master'
git merge 'Unity-Technologies/proper-param0xffff-fix'
git push origin 'master'
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil!977
No description provided.