Skip to content

fix: correct swapped Value field types in ElfSymbol32 and ElfSymbol64#1408

Merged
max-charlamb merged 2 commits intomainfrom
copilot/fix-issue-1407
Mar 23, 2026
Merged

fix: correct swapped Value field types in ElfSymbol32 and ElfSymbol64#1408
max-charlamb merged 2 commits intomainfrom
copilot/fix-issue-1407

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 20, 2026

Fixes #1407.

The Value field types were accidentally swapped between the two ELF symbol structs:

  • ElfSymbol32.Value was ulong (8 bytes) — should be uint (4 bytes per ELF spec Elf32_Addr)
  • ElfSymbol64.Value was uint (4 bytes) — should be ulong (8 bytes per ELF spec Elf64_Addr)

For 32-bit ELF, the over-sized ulong Value field was merging st_value and st_size into a single 8-byte read, causing GetExportSymbolAddress to return addresses with the symbol's st_size value leaked into the upper bits (e.g. returning 0x20EFCE9BA8 instead of 0xEFCE9BA8).

Also added the missing (long) cast in ElfSymbolTable.GetSymbol for the 64-bit path since Value is now correctly ulong.

Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@leculver leculver left a comment

Choose a reason for hiding this comment

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

Just double checked the underlying sources, this fix is correct...but it's surprising that it's been wrong for this long and we haven't noticed. :(

@max-charlamb max-charlamb merged commit 6f87d89 into main Mar 23, 2026
11 checks passed
@max-charlamb max-charlamb deleted the copilot/fix-issue-1407 branch March 23, 2026 14:13
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.

GetExportSymbolAddress returns corrupt addresses for 32-bit ELF modules

3 participants