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

ffi: Panic on incorrect FFI parameters #13280

Closed
fucksophie opened this issue Jan 4, 2022 · 1 comment · Fixed by #13283
Closed

ffi: Panic on incorrect FFI parameters #13280

fucksophie opened this issue Jan 4, 2022 · 1 comment · Fixed by #13283
Labels
bug Something isn't working correctly FFI Related to Foreign Function Interface APIs

Comments

@fucksophie
Copy link

fucksophie commented Jan 4, 2022

Code

const user32 = Deno.dlopen("user32.dll", {
    SystemParametersInfoA: {
        parameters: [
            "u32", 
            "u32",
            "pointer", 
            "u32", 
        ], 
        result: "i32" 
    } 
});

const result = user32.symbols.SystemParametersInfoA(0x0014, null, new TextEncoder().encode("D:/flower1.jpg"), 0x01)

Panic

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: windows x86_64
Version: 1.17.1
Args: ["deno", "run", "--unstable", "--allow-all", "natives.ts"]

thread 'main' panicked at 'Expected ffi arg value to be an unsigned integer', ext\ffi\lib.rs:281:6
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Mitigation

In this case, you can replace the null in user32.symbols.Syst... to 0, to match the symbol's parameters and the panic no longer occurs.

@bartlomieju bartlomieju added bug Something isn't working correctly FFI Related to Foreign Function Interface APIs labels Jan 4, 2022
@fucksophie
Copy link
Author

I think
64fe46b would fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly FFI Related to Foreign Function Interface APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants