Skip to content

RuntimeError: memory access out of bounds #68

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

Closed
ubaidsk opened this issue Feb 27, 2023 · 4 comments
Closed

RuntimeError: memory access out of bounds #68

ubaidsk opened this issue Feb 27, 2023 · 4 comments

Comments

@ubaidsk
Copy link
Member

ubaidsk commented Feb 27, 2023

          > Then check that everything works afterwards, otherwise you'll need to fix things.

Yes, checked. The site seems to work. We are facing this issue lfortran/lfortran#658 for the template_travel preinstalled example.

Steps to reproduce:

  • Open the site https://dev.lfortran.org in a browser.
  • Select template_travel example from the examples menu
  • Click on the WAT tab.

Output:

RuntimeError: memory access out of bounds
ERROR: WAT could not be generated from the code

Temporary Workaround:

  • Once on the WAT, click on the Run button.
Output
(module
    (type (;0;) (func (param i32) (result)))
    (type (;1;) (func (param i32 i32 i32 i32) (result i32)))
    (type (;2;) (func (param i64) (result)))
    (type (;3;) (func (param f64) (result)))
    (type (;4;) (func (param f32 f32) (result f32)))
    (type (;5;) (func (param f32 f32) (result f32)))
    (type (;6;) (func (param f32 f32 f32 f32) (result f32)))
    (type (;7;) (func (param f32 f32 f32 f32) (result f32)))
    (type (;8;) (func (param f32 f32 f32 f32) (result f32)))
    (type (;9;) (func (param) (result)))
    (type (;10;) (func (param) (result)))
    (import "wasi_snapshot_preview1" "proc_exit" (func (;0;) (type 0)))
    (import "wasi_snapshot_preview1" "fd_write" (func (;1;) (type 1)))
    (global $0 i32 (i32.const 0))
    (func $2 (type 2) (param i64) (result)
        (local i64 i64 i64 i64)
        local.get 0
        i64.const 0
        i64.eq
        if
            i32.const 1
            i32.const 52
            i32.const 1
            i32.const 0
            call 1
            drop
            return
        else
        end
        local.get 0
        i64.const 0
        i64.lt_s
        if
            i32.const 1
            i32.const 28
            i32.const 1
            i32.const 0
            call 1
            drop
            local.get 0
            i64.const -1
            i64.mul
            local.set 0
        else
        end
        local.get 0
        local.set 4
        i64.const 0
        local.set 1
        loop
            local.get 0
            i64.const 0
            i64.gt_s
            if
                local.get 1
                i64.const 1
                i64.add
                local.set 1
                local.get 0
                i64.const 10
                i64.div_s
                local.set 0
                br 1
            else
            end
        end
        loop
            local.get 1
            i64.const 0
            i64.gt_s
            if
                local.get 1
                i64.const 1
                i64.sub
                local.set 1
                i64.const 1
                local.set 2
                i64.const 0
                local.set 3
                loop
                    local.get 3
                    local.get 1
                    i64.lt_s
                    if
                        local.get 3
                        i64.const 1
                        i64.add
                        local.set 3
                        local.get 2
                        i64.const 10
                        i64.mul
                        local.set 2
                        br 1
                    else
                    end
                end
                local.get 4
                local.get 2
                i64.div_s
                i64.const 10
                i64.rem_s
                i64.const 12
                i64.mul
                i64.const 52
                i64.add
                local.set 0
                i32.const 1
                local.get 0
                i32.wrap_i64
                i32.const 1
                i32.const 0
                call 1
                drop
                br 1
            else
            end
        end
        return
    )
    (func $3 (type 3) (param f64) (result)
        (local i64 i64 i64)
        local.get 0
        f64.const 0.000000
        f64.lt
        if
            i32.const 1
            i32.const 28
            i32.const 1
            i32.const 0
            call 1
            drop
            local.get 0
            f64.const -1.000000
            f64.mul
            local.set 0
        else
        end
        local.get 0
        i64.trunc_f64_s
        call 2
        i32.const 1
        i32.const 40
        i32.const 1
        i32.const 0
        call 1
        drop
        local.get 0
        local.get 0
        i64.trunc_f64_s
        f64.convert_i64_s
        f64.sub
        f64.const 100000000.000000
        f64.mul
        i64.trunc_f64_s
        local.set 2
        local.get 2
        local.set 3
        i64.const 0
        local.set 1
        loop
            local.get 2
            i64.const 0
            i64.gt_s
            if
                local.get 1
                i64.const 1
                i64.add
                local.set 1
                local.get 2
                f64.convert_i64_s
                i64.const 10
                f64.convert_i64_s
                f64.div
                i64.trunc_f64_s
                local.set 2
                br 1
            else
            end
        end
        loop
            local.get 1
            i64.const 8
            i64.lt_s
            if
                local.get 1
                i64.const 1
                i64.add
                local.set 1
                i32.const 1
                i32.const 52
                i32.const 1
                i32.const 0
                call 1
                drop
                br 1
            else
            end
        end
        local.get 3
        call 2
        return
    )
    (func $4 (type 4) (param f32 f32) (result f32)
        (local f32)
        local.get 0
        local.get 1
        f32.add
        local.set 2
        local.get 2
        return
    )
    (func $5 (type 5) (param f32 f32) (result f32)
        (local f32)
        local.get 0
        local.get 1
        f32.div
        local.set 2
        local.get 2
        return
    )
    (func $6 (type 6) (param f32 f32 f32 f32) (result f32)
        (local f32)
        local.get 0
        local.get 2
        call 4
        local.get 1
        local.get 3
        call 4
        call 5
        local.set 4
        local.get 4
        return
    )
    (func $7 (type 7) (param f32 f32 f32 f32) (result f32)
        (local f32)
        local.get 0
        local.get 0
        local.get 1
        call 5
        local.get 2
        local.get 2
        local.get 3
        call 5
        call 6
        local.set 4
        local.get 4
        return
    )
    (func $8 (type 8) (param f32 f32 f32 f32) (result f32)
        (local f32)
        local.get 0
        local.get 2
        call 4
        local.get 1
        local.get 3
        call 4
        call 5
        local.set 4
        local.get 4
        return
    )
    (func $9 (type 9) (param) (result)
        (local f32 f32)
        f32.const 1.000000
        f32.const 3.000000
        f32.const 1.500000
        f32.const 4.000000
        call 8
        local.set 0
        f32.const 1.100000
        f32.const 0.500000
        f32.const 2.000000
        f32.const 0.750000
        call 7
        local.set 1
        i32.const 1
        i32.const 172
        i32.const 1
        i32.const 0
        call 1
        drop
        i32.const 1
        i32.const 4
        i32.const 1
        i32.const 0
        call 1
        drop
        local.get 0
        f64.promote_f32
        call 3
        i32.const 1
        i32.const 16
        i32.const 1
        i32.const 0
        call 1
        drop
        i32.const 1
        i32.const 184
        i32.const 1
        i32.const 0
        call 1
        drop
        i32.const 1
        i32.const 4
        i32.const 1
        i32.const 0
        call 1
        drop
        local.get 1
        f64.promote_f32
        call 3
        i32.const 1
        i32.const 16
        i32.const 1
        i32.const 0
        call 1
        drop
        return
    )
    (func $10 (type 10) (param) (result)
        (local)
        call 9
        i32.const 0
        call 0
        return
    )
    (memory (;0;) 100 100)
    (export "memory" (memory 0))
    (export "print_i64" (func 2))
    (export "print_f64" (func 3))
    (export "add_real" (func 4))
    (export "slash_real" (func 5))
    (export "__asr_generic_avg_s_from_t" (func 6))
    (export "avg_real_s_from_s" (func 7))
    (export "avg_real_s_from_t" (func 8))
    (export "test_template" (func 9))
    (export "_start" (func 10))
    (data (;0;) (i32.const 4) "\0c\00\00\00\01\00\00\00")
    (data (;1;) (i32.const 12) "    ")
    (data (;2;) (i32.const 16) "\18\00\00\00\01\00\00\00")
    (data (;3;) (i32.const 24) "\0a   ")
    (data (;4;) (i32.const 28) "\24\00\00\00\01\00\00\00")
    (data (;5;) (i32.const 36) "-   ")
    (data (;6;) (i32.const 40) "\30\00\00\00\01\00\00\00")
    (data (;7;) (i32.const 48) ".   ")
    (data (;8;) (i32.const 52) "\3c\00\00\00\01\00\00\00")
    (data (;9;) (i32.const 60) "0   ")
    (data (;10;) (i32.const 64) "\48\00\00\00\01\00\00\00")
    (data (;11;) (i32.const 72) "1   ")
    (data (;12;) (i32.const 76) "\54\00\00\00\01\00\00\00")
    (data (;13;) (i32.const 84) "2   ")
    (data (;14;) (i32.const 88) "\60\00\00\00\01\00\00\00")
    (data (;15;) (i32.const 96) "3   ")
    (data (;16;) (i32.const 100) "\6c\00\00\00\01\00\00\00")
    (data (;17;) (i32.const 108) "4   ")
    (data (;18;) (i32.const 112) "\78\00\00\00\01\00\00\00")
    (data (;19;) (i32.const 120) "5   ")
    (data (;20;) (i32.const 124) "\84\00\00\00\01\00\00\00")
    (data (;21;) (i32.const 132) "6   ")
    (data (;22;) (i32.const 136) "\90\00\00\00\01\00\00\00")
    (data (;23;) (i32.const 144) "7   ")
    (data (;24;) (i32.const 148) "\9c\00\00\00\01\00\00\00")
    (data (;25;) (i32.const 156) "8   ")
    (data (;26;) (i32.const 160) "\a8\00\00\00\01\00\00\00")
    (data (;27;) (i32.const 168) "9   ")
    (data (;28;) (i32.const 172) "\b4\00\00\00\03\00\00\00")
    (data (;29;) (i32.const 180) "s1= ")
    (data (;30;) (i32.const 184) "\c0\00\00\00\03\00\00\00")
    (data (;31;) (i32.const 192) "s2= ")
)

Originally posted by @Shaikh-Ubaid in #64 (comment)

Related lfortran/lfortran#658

@ubaidsk
Copy link
Member Author

ubaidsk commented Mar 25, 2023

I am unable to reproduce the above error. (I think it probably got fixed on using newer lfortran. Recent lfortran versions support removing unused subroutines. I guess after removing unused subroutines, the memory required during wasm compilation and/or wat construction is not exceeding the bounds).

Please open up an issue for this, so that we don't forget. After doing Command+Shift+R in Firefox, I can now reproduce the issue and workaround.

@certik you shared here #64 (comment) that you were able to reproduce it. Please, could you check again and share if you are able to reproduce the error?

@certik
Copy link
Contributor

certik commented Mar 25, 2023

I can't reproduce it anymore either.

@ubaidsk
Copy link
Member Author

ubaidsk commented Mar 25, 2023

Shall we close this issue or shall we keep it open? We also have a similar issue open at lfortran/lfortran#658.

@certik
Copy link
Contributor

certik commented Mar 25, 2023

Let's close this if we can't reproduce it. If it happens again, we'll investigate then.

@certik certik closed this as completed Mar 25, 2023
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

No branches or pull requests

2 participants