Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Getting integer divide by zero error when use compress/gzip #41

Closed
qq906907952 opened this issue Nov 27, 2023 · 3 comments · Fixed by #42
Closed

Getting integer divide by zero error when use compress/gzip #41

qq906907952 opened this issue Nov 27, 2023 · 3 comments · Fixed by #42

Comments

@qq906907952
Copy link

qq906907952 commented Nov 27, 2023

I was use this library with a wasi module written in Go to enhance the performance, but i encounter an error with
panic: runtime error: divide by zero
when i use compress/gzip stdlib to decode gzip bytes.

the full compile command:
tinygo build -o wasm.wasm -target wasi -gc=custom -tags=custommalloc -target=wasi -scheduler=none ./main.go

i run it with wasmtime:
env WASMTIME_BACKTRACE_DETAILS=1 wasmtime wasm.wasm

panic: runtime error: divide by zero
Error: failed to run main module `wasm.wasm`

Caused by:
    0: failed to invoke command default
    1: error while executing at wasm backtrace:
           0: 0x24d61 - runtime.abort
                           at /root/software/tinygo/src/runtime/runtime_tinygowasm.go:70:6              - runtime.runtimePanicAt
                           at /root/software/tinygo/src/runtime/panic.go:71:7
           1: 0x27519 - runtime.divideByZeroPanic
                           at /root/software/tinygo/src/runtime/panic.go:177:16
           2: 0x1cf57 - runtime.alloc
                           at /root/workplace/go_poject/GOPATH/pkg/mod/github.com/wasilibs/nottinygc@v0.7.0/intmap.go:93:19
           3: 0x23408 - compress/flate.newHuffmanEncoder
                           at /root/.g/go/.versions/1.21.3/src/compress/flate/huffman_code.go:60:24
           4: 0x22609 - compress/flate.generateFixedOffsetEncoding
                           at /root/.g/go/.versions/1.21.3/src/compress/flate/huffman_code.go:95:24              - runtime.run
                           at /root/software/tinygo/src/runtime/scheduler_none.go:24:9              - _start
                           at /root/software/tinygo/src/runtime/runtime_wasm_wasi.go:21:5

when i remove the gzip lib, everything is working fine

tinygo version:
tinygo version 0.30.0 linux/amd64 (using go version go1.21.3 and LLVM version 16.0.1)

@anuraaga
Copy link
Contributor

Hi @qq906907952 - thanks for the report. I will try to reproduce using the gzip library, but are you able to provide a code reproduction? Thanks.

@qq906907952
Copy link
Author

qq906907952 commented Nov 27, 2023

Hi @qq906907952 - thanks for the report. I will try to reproduce using the gzip library, but are you able to provide a code reproduction? Thanks.

of course,there is the very simple code to reproduce the error

package main

import (
	"bytes"
	"compress/gzip"
	_ "github.com/wasilibs/nottinygc"
)

func main() {
	r := bytes.NewReader([]byte{})
	gzip.NewReader(r)
}

compile with
tinygo build -o wasm.wasm -target wasi -gc=custom -tags=custommalloc -target=wasi -scheduler=none ./main.go

@anuraaga
Copy link
Contributor

Thanks a lot for the repro @qq906907952! I have released 0.7.1 with a fix for the bug.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants