Skip to content

Fix IndexOutOfRangeException in PEImage.DoRead relocation handling#1360

Merged
leculver merged 1 commit intomicrosoft:mainfrom
leculver:issue_1288
Feb 18, 2026
Merged

Fix IndexOutOfRangeException in PEImage.DoRead relocation handling#1360
leculver merged 1 commit intomicrosoft:mainfrom
leculver:issue_1288

Conversation

@leculver
Copy link
Contributor

Fix bug where negative BinarySearch results were used as array indices instead of their bitwise complements in DoRead's relocation handling.

beginSearch Case 3: beginRelocation = beginSearch - 1 -> beginSearchComplement - 1
endSearch Case 3: endRelocation = endSearch -> endSearchComplement

Fixes #1288

Fix bug where negative BinarySearch results were used as array indices
instead of their bitwise complements in DoRead's relocation handling.

beginSearch Case 3: beginRelocation = beginSearch - 1 -> beginSearchComplement - 1
endSearch Case 3: endRelocation = endSearch -> endSearchComplement

Fixes microsoft#1288
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a crash in ClrMD’s PE image reader (PEImage.DoRead) when applying relocations by correctly handling negative Array.BinarySearch results (using the bitwise complement insertion index instead of the negative return value). This aligns with the reported IndexOutOfRangeException in issue #1288 and improves robustness when reading PE data from partial/virtualized sources (e.g., dumps produced by dotnet-monitor).

Changes:

  • Corrected relocation start index calculation when the read begins inside a relocation (use beginSearchComplement - 1).
  • Corrected relocation end index calculation when the read ends inside a relocation (use endSearchComplement).
  • Updated related Debug.Assert checks to validate the corrected indices.

@leculver leculver merged commit 948b358 into microsoft:main Feb 18, 2026
14 checks passed
@leculver leculver deleted the issue_1288 branch February 18, 2026 20:27
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.

IndexOutOfRangeException

2 participants

Comments