Harden debug scope update logic #824

Merged
vitek-karas merged 2 commits from HardenDebugScopeUpdate into master 2022-01-19 17:07:41 -06:00
vitek-karas commented 2022-01-13 05:50:19 -06:00 (Migrated from github.com)

Based on bug reports like #816 it seems there are still cases where the IL and scope offsets are out of sync in weird ways. This change modifies the logic to have no potential to cause the IndexOutOfRangeException. While I was not able to determine what combination could cause this, it's better this way.

The corner case comes when there's potential problem with the first/second instruction in the method body. The change in this case will potentially make the debug scopes slightly wrong by not pointing to the previous instruction (as there's none). Without having a real repro it's hard to tell what would be a better solution, this way it won't crash and the scopes still make sense.

Based on bug reports like #816 it seems there are still cases where the IL and scope offsets are out of sync in weird ways. This change modifies the logic to have no potential to cause the `IndexOutOfRangeException`. While I was not able to determine what combination could cause this, it's better this way. The corner case comes when there's potential problem with the first/second instruction in the method body. The change in this case will potentially make the debug scopes slightly wrong by not pointing to the previous instruction (as there's none). Without having a real repro it's hard to tell what would be a better solution, this way it won't crash and the scopes still make sense.
vitek-karas commented 2022-01-13 05:50:34 -06:00 (Migrated from github.com)

/cc @SteveGilham

/cc @SteveGilham
SteveGilham (Migrated from github.com) reviewed 2022-01-14 03:34:14 -06:00
SteveGilham (Migrated from github.com) left a comment

The ubiquitous return new InstructionOffset (i == 0 ? items [0] : items [i - 1]); seems like a reasonable precaution.

The ubiquitous `return new InstructionOffset (i == 0 ? items [0] : items [i - 1]);` seems like a reasonable precaution.
jbevain commented 2022-01-19 17:07:48 -06:00 (Migrated from github.com)

Thank you!

Thank you!
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!824
No description provided.