m4b / m4b/goblin

`vm_range` is lossy on 32-bit platforms reading 64-bit objects

Open
#285 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.5k
Forks
202
PR merge metrics
No merged PRs in 30d

Description

The current implementations of `SectionHeader::vm_range` and `ProgramHeader::vm_range` look like this:

```rust
/// Returns this section header's virtual memory range
pub fn vm_range(&self) -> Range {
self.sh_addr as usize..(self.sh_addr as usize).saturating_add(self.sh_size as usize)
}
```

Those `as usize` casts are silent truncating casts on 32-bit platforms when the input object is 64 bit. This also means the `saturating_add` is subtly wrong, since it will saturate to the current host's `usize::MAX` rather than the actual end of section in the file. The return type of `vm_range` probably ought to be `Range` to match the size of `sh_addr`/`sh_size` and friends, or be a `Result`/`Option` to indicate cases where the offset/size in the file are not representable in the host `usize` type.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the implementations of SectionHeader::vm_range and ProgramHeader::vm_range, then inspect their callers to understand the expected range type and error behavior. Check the behavior when 64-bit object values are read on 32-bit platforms; done means the API no longer silently loses address or size information and its tests cover the affected cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
reverse-engineering
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.