Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix off-by-one in offset_from_vma #74

Merged
merged 1 commit into from
Apr 21, 2024
Merged

Conversation

Bo98
Copy link
Contributor

@Bo98 Bo98 commented Apr 15, 2024

Consider the following ELF file:

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
[...]
  LOAD           0x02cfa8 0x000000000002dfa8 0x000000000002dfa8 0x001580 0x002058 RW  0x1000
  LOAD           0x03e000 0x0000000000030000 0x0000000000030000 0x0097c0 0x0097c0 RW  0x1000
[...]

Before this pull request, offset_from_vma(0x30000) would return 0x2F000 which is a part of the first segment when it instead should be the first offset of the latter segment, i.e. 0x3E000.

This was due to the default size of zero. vma_in? searches from the offset inclusive to the offset + size exclusive. When size = 0 the starting offset is counted as exclusive and thus uses the first segment. For correct calculations, the minimum range must be 1.

@david942j
Copy link
Owner

Thank you for the fix!

@david942j david942j merged commit e5677a0 into david942j:master Apr 21, 2024
13 checks passed
@Bo98 Bo98 deleted the vma-fix branch April 21, 2024 20:23
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