I'm building a Go wasm module (compiled with TinyGo) and it compiles fine. But when I try to run it in the browser I get the above error.

1

There are 1 best solutions below

0
On

In resolution with the workaround post in the bug report, you can fix this bug if it's caused by the use of sha256.Sum or sha256.Write by editing the function in your $GOROOT/src/crypto/sha256/sha256block.go to:

func blockGeneric(dig *digest, p []byte) {
    var w [64]uint32
    h0, h1, h2, h3, h4, h5, h6, h7 := dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7]
    for WorkAround1 := 0; WorkAround1 < len(p); WorkAround1 += chunk {
        WorkAround2 := p[WorkAround1:]
    //for len(p) >= chunk {
        // Can interlace the computation of w with the
        // rounds below if needed for speed.
        for i := 0; i < 16; i++ {
            j := i * 4
            w[i] = uint32(WorkAround2[j])<<24 | uint32(WorkAround2[j+1])<<16 | uint32(WorkAround2[j+2])<<8 | uint32(WorkAround2[j+3])
        }
        for i := 16; i < 64; i++ {
            v1 := w[i-2]
            t1 := (v1>>17 | v1<<(32-17)) ^ (v1>>19 | v1<<(32-19)) ^ (v1 >> 10)
            v2 := w[i-15]
            t2 := (v2>>7 | v2<<(32-7)) ^ (v2>>18 | v2<<(32-18)) ^ (v2 >> 3)
            w[i] = t1 + w[i-7] + t2 + w[i-16]
        }

        a, b, c, d, e, f, g, h := h0, h1, h2, h3, h4, h5, h6, h7

        for i := 0; i < 64; i++ {
            t1 := h + ((e>>6 | e<<(32-6)) ^ (e>>11 | e<<(32-11)) ^ (e>>25 | e<<(32-25))) + ((e & f) ^ (^e & g)) + _K[i] + w[i]

            t2 := ((a>>2 | a<<(32-2)) ^ (a>>13 | a<<(32-13)) ^ (a>>22 | a<<(32-22))) + ((a & b) ^ (a & c) ^ (b & c))

            h = g
            g = f
            f = e
            e = d + t1
            d = c
            c = b
            b = a
            a = t1 + t2
        }

        h0 += a
        h1 += b
        h2 += c
        h3 += d
        h4 += e
        h5 += f
        h6 += g
        h7 += h
        //p = p[chunk:]
    }

    dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7] = h0, h1, h2, h3, h4, h5, h6, h7

}