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

Apparent bounds checking failure #1952

Closed
Programmerino opened this issue May 28, 2023 · 1 comment
Closed

Apparent bounds checking failure #1952

Programmerino opened this issue May 28, 2023 · 1 comment
Labels

Comments

@Programmerino
Copy link

It's possible to read past the end of arrays without using unsafe, sometimes leading to segfaults. I tested it on the C backend on both 761c9de (current master) and 0.24.3 (latest release). My compiler is gcc version 13.1.1 and I am on x86-64 Linux.

I have two examples, the first one is simple but the returned value always seems to be x and I can't achieve a segfault with it:

entry main (x: i64) =
    let is = flatten [[x], [x]]
    in
    is[999999999]

Output:

> futhark c bad.fut
> echo "0" | ./bad --entry-point main
0i64

Here is the second one:

def helper inner outer =
    let is = flatten (map(\_ -> inner |> map id) outer)
    in
    is[999999999]

entry main (_: i64) = helper [(1i32, 0i32), (0, 0)] [(0, 0)]

Output:

> futhark c bad.fut
> echo "0" | ./bad --entry-point main
Segmentation fault (core dumped)
@athas
Copy link
Member

athas commented May 28, 2023

The first one is benign, because the compiler realises that the output (if any) must be zero. We still normally try to preserve failing checks, though.

The second one is a real problem and is likely due to a sloppy rewrite rule that throws away safety dependencies.

@athas athas added the bug label May 28, 2023
@athas athas closed this as completed in 61aa9fe May 28, 2023
razetime pushed a commit to razetime/futhark that referenced this issue Jul 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants