microsoft / microsoft/injectorppforrust

`std::any::type_name_of_val` can't guarantee different strings for different types

Open
#72 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
404
Forks
19
Avg merge
23h 57m
Merged PRs (30d)
1

Description

Currently the API relies upon std::any::type_name_of_val to check that the hooked function and the replacement function has the same signature.

From the documentation for type_name:

The returned string must not be considered to be a unique identifier of a type as multiple types may map to the same type name.

and type_name_of_val:

In short: use this for debugging, avoid using the output to affect program behavior

Here is an example repo where injectorpp thinks to function types are the same, but they are not, causing undefined behavior: https://github.com/tyilo/injectorpp-ub

You should be able to avoid this by introducing a generic type for the actual type of the function, something like:

impl InjectorPP {
    pub fn when_called(&mut self, func: FuncPtr<T>) -> WhenCalledBuilder<'_, T> {
        ...
    }
}

impl WhenCalledBuilder<'_, T> {
    pub fn will_execute_raw(self, target: FuncPtr<T>) {
        ...
    }
}

Contributor guide

Open the contributing guide

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 by locating the implementation of when_called and will_execute_raw, then inspect how std::any::type_name_of_val compares function signatures. Use the linked injectorpp-ub example to understand the failure; done means signature validation no longer depends on type-name strings and the proposed generic function types are supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.